/*
define([
		'js/_services/module.js'
		,'jquery'
		,'common'
//        ,'js/_services/systemService.js'

//        ,'js/_services/uServiceCenter.js'

        //////////////////数组组件//////////////////////
//        ,'js/_services/BizData.min.js'
        //////////////////////////////////////////
        
        
//      ,'js/_services/accessMarksService.js'
        //////////////////钉钉测试//////////////////////
//        ,'js/_services/dingtalkService.js'
        //////////////////////////////////////////

//        ,'js/_services/personService.js'
//        ,'js/_services/permissionService.js'//角色分配权限使用使用
//        ,'js/_services/billSettingService.js'//单据设置使用
//        ,'js/_services/sysInfoOrgService.js'//应用商店使用
//        ,'js/_services/securityService.js'
        
        
//        ,'js/_services/processService.js'
//        ,'js/_services/taxTypeService.js'
//        ,'js/_services/planTypeService.js'
//        ,'js/_services/costingTypeService.js'
//        ,'js/_services/qualityTypeService.js'
//        ,'js/_services/qualityStatusService.js'
//        ,'js/_services/dataDictionaryService.js'
        
        ],function(services,$,common){
*/

define(['angular' ,'jquery' ,'common','uiBootstrap' ],function(angular,$,common){
	var services = angular.module('app.services', ['ui.bootstrap']);
	//	console.log('三模块通用服务services被加载！');
//	console.log('services-->',services);
	
    'use strict';
	
	//安全信息管理服务
    services.factory('securityService',['$rootScope','$http',f])
	function f($rootScope,$http){
    	
		var _self = this;

		//获取当前用户对象
		var getCurrentPerson = function(async){
			//async:异步调用参数，默认值为异步调用true
			var asyncParam = true;
			if(!angular.isDefined(async)){
			}else{
				asyncParam = async;
			}

			//$http服务只有异步没有同步，只能使用jquery的ajax
			if(asyncParam == true){
				var response = $http({
					method : 'GET'
					,url : $rootScope.getServiceName() + '/security/personInfo/getCurrentPerson'
//					,data:  data
				});	
				return response;
			}

			//jquery同步调用
			if(asyncParam == false){
				var response = $.ajax({
		            type: "GET",
		            async : false,
		            url: $rootScope.getServiceName() + "/security/personInfo/getCurrentPerson",
//		            data: "{}",
		            contentType: "application/json; charset=utf-8",
		            dataType: "json",
		            success: function (data) {
		                // Play with returned data in JSON format
		            },
		            error: function (msg) {
		                alert(msg.responseText);
		            }
		        });
				if (response.readyState == 4 && response.status == 200) {
					return response.responseJSON;
				}else{
					return '';
				}
			}
			
		};
		
		//获取当前用户主要人员成员对象
		var getMainPersonMember = function(async){
			//async:异步调用参数，默认值为异步调用true
			var asyncParam = true;
			if(!angular.isDefined(async)){
			}else{
				asyncParam = async;
			}

			//$http服务只有异步没有同步，只能使用jquery的ajax
			if(asyncParam == true){
				var response = $http({
					method : 'GET'
					,url : $rootScope.getServiceName() + '/usercenter/org/getMainPersonMember'
//					,data:  data
				});	
				return response;
			}

			//jquery同步调用
			if(asyncParam == false){
				var response = $.ajax({
		            type: "GET",
		            async : false,
		            url: $rootScope.getServiceName() + "/usercenter/org/getMainPersonMember",
//		            data: "{}",
		            contentType: "application/json; charset=utf-8",
		            dataType: "json",
		            success: function (data, textStatus) {
		                // Play with returned data in JSON format
		            },
		            error: function (XMLHttpRequest, textStatus, errorThrown) {
		            }
		        });
				if (response.readyState == 4 && response.status == 200) {
					if(response.responseJSON.status.statusFlag=='success'){
						return response.responseJSON.data;
					}else{
						return null;
					}
				}else{
					var msg = '$.ajax调用失败！';
					alert(msg);
								
					return null;
				}
			}
			
		};
		
		//获取人员成员信息及其所属公司
		var getPersonMemberInfo = function(sID,async){
			//async:异步调用参数，默认值为异步调用true
			var asyncParam = true;
			if(!angular.isDefined(async)){
			}else{
				asyncParam = async;
			}

			//$http服务只有异步没有同步，只能使用jquery的ajax
			if(asyncParam == true){
				var response = $http({
					method : 'GET'
					,url : $rootScope.getServiceName() + '/usercenter/org/getPersonMemberInfo'
//					,data:  data
				});	
				return response;
			}

			//jquery同步调用
			if(asyncParam == false){
				var response = $.ajax({
		            type: "GET",
		            async : false,
		            url: $rootScope.getServiceName() + "/usercenter/org/getPersonMemberInfo",
		            data: {"id":sID},
		            contentType: "application/json; charset=utf-8",
		            dataType: "json",
		            success: function (data, textStatus) {
		                // Play with returned data in JSON format
		            },
		            error: function (XMLHttpRequest, textStatus, errorThrown) {
		            }
		        });
				if (response.readyState == 4 && response.status == 200) {
					if(response.responseJSON.status.statusFlag=='success'){
						return response.responseJSON.data;
					}else{

						return null;
					}
				}else{
					var msg = '$.ajax调用失败！';
					alert(msg);

					return null;
				}
			}
			
		};
		var getPersonMemberInfoByFID = function(sID,async){
			//async:异步调用参数，默认值为异步调用true
			var asyncParam = true;
			if(!angular.isDefined(async)){
			}else{
				asyncParam = async;
			}

			//$http服务只有异步没有同步，只能使用jquery的ajax
			if(asyncParam == true){
				var response = $http({
					method : 'GET'
					,url : $rootScope.getServiceName() + '/usercenter/org/getPersonMemberInfoByFID'
//					,data:  data
				});	
				return response;
			}

			//jquery同步调用
			if(asyncParam == false){
				var response = $.ajax({
		            type: "GET",
		            async : false,
		            url: $rootScope.getServiceName() + "/usercenter/org/getPersonMemberInfoByFID",
		            data: {"id":sID},
		            contentType: "application/json; charset=utf-8",
		            dataType: "json",
		            success: function (data, textStatus) {
		                // Play with returned data in JSON format
		            },
		            error: function (XMLHttpRequest, textStatus, errorThrown) {
		            }
		        });
				if (response.readyState == 4 && response.status == 200) {
					if(response.responseJSON.status.statusFlag=='success'){
						return response.responseJSON.data;
					}else{

						return null;
					}
				}else{
					var msg = '$.ajax调用失败！';
					alert(msg);
								
					return null;
				}
			}
			
		};
		
		//获取当前用户主要人员成员对象
		var getCurrentPsmList = function(async){
			//async:异步调用参数，默认值为异步调用true
			var asyncParam = true;
			if(!angular.isDefined(async)){
			}else{
				asyncParam = async;
			}

			//$http服务只有异步没有同步，只能使用jquery的ajax
			if(asyncParam == true){
				var response = $http({
					method : 'GET'
					,url : $rootScope.getServiceName() + '/usercenter/orgInfo/getCurrentPsmList'
//					,data:  data
				});	
				return response;
			}

			//jquery同步调用
			if(asyncParam == false){
				var response = $.ajax({
		            type: "GET",
		            async : false,
		            url: $rootScope.getServiceName() + "//usercenter/orgInfo/getCurrentPsmList",
//		            data: "{}",
		            contentType: "application/json; charset=utf-8",
		            dataType: "json",
		            success: function (data, textStatus) {
		                // Play with returned data in JSON format
		            },
		            error: function (XMLHttpRequest, textStatus, errorThrown) {
		            }
		        });
				if (response.readyState == 4 && response.status == 200) {
					if(response.responseJSON.status.statusFlag=='success'){
						return response.responseJSON.data;
					}else{
						alert('获取人员成员列表失败!');

						return null;
					}
				}else{
					var msg = '$.ajax调用失败！';
					alert(msg);

					return null;
				}
			}
			
		};
		
		//获取当前用户主要人员成员对象
		var getCurrentOgnList = function(async){
			//async:异步调用参数，默认值为异步调用true
			var asyncParam = true;
			if(!angular.isDefined(async)){
			}else{
				asyncParam = async;
			}

			//$http服务只有异步没有同步，只能使用jquery的ajax
			if(asyncParam == true){
				var response = $http({
					method : 'GET'
					,url : $rootScope.getServiceName() + '/usercenter/orgInfo/getCurrentOgnList'
//					,data:  data
				});	
				return response;
			}

			//jquery同步调用
			if(asyncParam == false){
				var response = $.ajax({
		            type: "GET",
		            async : false,
		            url: $rootScope.getServiceName() + "/usercenter/orgInfo/getCurrentOgnList",
//		            data: "{}",
		            contentType: "application/json; charset=utf-8",
		            dataType: "json",
		            success: function (data, textStatus) {
		                // Play with returned data in JSON format
		            },
		            error: function (XMLHttpRequest, textStatus, errorThrown) {
		            }
		        });
				if (response.readyState == 4 && response.status == 200) {
					if(response.responseJSON.status.statusFlag=='success'){
						return response.responseJSON.data;
					}else{
						alert('获取人员成员列表失败!');

						return null;
					}
				}else{
					var msg = '$.ajax调用失败！';
					alert(msg);

					return null;
				}
			}
			
		};

		var getOgnsBysCreatorFID = function(sCreatorFID){
			
			var response = $http({
				method : 'POST'
				,url : $rootScope.getServiceName() + '/usercenter/orgInfo/getOgnsBysCreatorFID'
//			    ,data : {'username':'$scope.username','userlabel':'$scope.userlabe'}
	    		,data : {'sCreatorFID':sCreatorFID}
			});	
			return response;
			
			/*
			var response = $.ajax({
	            type: "POST",
	            async : false,
	            url: "/u2/usercenter/orgInfo/getOgnsBysCreatorFID",
	            data: JSON.stringify({'sCreatorFID':sCreatorFID}),
	            contentType: "application/json; charset=utf-8",
	            dataType: "json",
	            success: function (data) {
	                // Play with returned data in JSON format
	            },
	            error: function (msg) {
	                alert(msg.responseText);
	            }
	        });
			if (response.readyState == 4 && response.status == 200) {
				return response.responseJSON;
			}else{
				return '';
			}
			*/
		};

		var getPersonOgnList = function(){
			var response = $http({
				method : 'GET'
				,url : $rootScope.getServiceName() + '/usercenter/org/getPersonOgnList'
//			    ,data : {'username':'$scope.username','userlabel':'$scope.userlabe'}
//	    		,data : data
			});	
			return response;
		};
		
		//获取当前人员成员
		var getCurrentPsm = function(async){
			//async:异步调用参数，默认值为异步调用true
			var asyncParam = true;
			if(!angular.isDefined(async)){
			}else{
				asyncParam = async;
			}

			//$http服务只有异步没有同步，只能使用jquery的ajax
			if(asyncParam == true){
				var response = $http({
					method : 'GET'
					,url : $rootScope.getServiceName() + '/usercenter/orgInfo/getCurrentPsm'
//					,data:  data
				});	
				return response;
			}

			//jquery同步调用
			if(asyncParam == false){
				var response = $.ajax({
		            type: "GET",
		            async : false,
		            url: $rootScope.getServiceName() + "/usercenter/orgInfo/getCurrentPsm",
//		            data: "{}",
		            contentType: "application/json; charset=utf-8",
		            dataType: "json",
		            success: function (data) {
		                // Play with returned data in JSON format
		            },
		            error: function (msg) {
		                alert(msg.responseText);
		            }
		        });
				if (response.readyState == 4 && response.status == 200) {
					return response.responseJSON;
				}else{
					return '';
				}
			}
			
		};
		
		//获取当前组织对象
		var getCurrentOgn = function(async){
			//async:异步调用参数，默认值为异步调用true
			var asyncParam = true;
			if(!angular.isDefined(async)){
			}else{
				asyncParam = async;
			}

			//$http服务只有异步没有同步，只能使用jquery的ajax
			if(asyncParam == true){
				var response = $http({
					method : 'GET'
					,url : $rootScope.getServiceName() + '/usercenter/orgInfo/getCurrentOgn'
//					,data:  data
				});	
				return response;
			}

			//jquery同步调用
			if(asyncParam == false){
				var response = $.ajax({
		            type: "GET",
		            async : false,
		            url: $rootScope.getServiceName() + "/usercenter/orgInfo/getCurrentOgn",
//		            data: "{}",
		            contentType: "application/json; charset=utf-8",
		            dataType: "json",
		            success: function (data) {
		                // Play with returned data in JSON format
		            },
		            error: function (msg) {
		                alert(msg.responseText);
		            }
		        });
				if (response.readyState == 4 && response.status == 200) {
					return response.responseJSON;
				}else{
					return '';
				}
			}
			
		};
		
		//获取当前门店或者工厂
		var getPersonFactory = function(data){
			var response = $http({
				method : 'POST'
				,url : $rootScope.getServiceName() + '/usercenter/personOrg/getPersonFactory'
				,data:  data
			});	
			return response;
		};
		
		/*
		this.getCurrentOgnID = function(async){
			var response = _self.getCurrentOgn(async);
			
			if(response==''){
				return '';
			}else{
				return response.sID;
			}
		};
		*/

		var getUpdatePersonEmail = function(data){
			var response = $http({
				method : 'POST'
				,url : $rootScope.getServiceName() + '/security/personInfo/updateEmail'
				,data:  data
			});	
			return response;
		};
		var getUpdatePersonPassword = function(data){
			var response = $http({
				method : 'POST'
				,url : $rootScope.getServiceName() + '/security/personInfo/updatePassword'
				,data:  data
			});	
			return response;
		};
		//设置主岗
		var getUpdateMainOrgByID = function(data){
			var response = $http({
				method : 'POST'
				,url : $rootScope.getServiceName() + '/security/person/updateMainOrgByID'
				,data:  data
			});	
			return response;
		};
		
		

		
		return {
			getCurrentPerson: function(async){
				return getCurrentPerson(async);
			}/*,
			getCurrentPersonID: function(async){
				return _self.getCurrentPersonID(async);
			},
			getCurrentLoginName: function(async){
				return _self.getCurrentLoginName(async);
			}*/,
			getOgnsBysCreatorFID: function(sCreatorFID){
				return getOgnsBysCreatorFID(sCreatorFID);
			},
			getPersonOgnList: function(){
				return getPersonOgnList();
			},
			getMainPersonMember: function(async){
				return getMainPersonMember(async);
			},
			getPersonMemberInfo: function(sID,async){
				return getPersonMemberInfo(sID,async);
			},
			getPersonMemberInfoByFID: function(sID,async){
				return getPersonMemberInfoByFID(sID,async);
			},
			getCurrentPsmList: function(async){
				return getCurrentPsmList(async);
			},
			getCurrentOgnList: function(async){
				return getCurrentOgnList(async);
			},
			getCurrentPsm: function(async){
				return getCurrentPsm(async);
			},
			getCurrentOgn: function(async){
				return getCurrentOgn(async);
			},
			getPersonFactory: function(data){
				return getPersonFactory(data);
			}/*,
			getCurrentOgnID: function(async){
				return _self.getCurrentOgnID(async);
			}*/,
			updatePersonEmail: function(data){
				return getUpdatePersonEmail(data);
			},
			updatePersonPassword: function(data){
				return getUpdatePersonPassword(data);
			},
			getUpdateMainOrgByID: function(data){
				return getUpdateMainOrgByID(data);
			}
		};
	}

    
	//usercenter模块专用，用于修改密码、邮件和配置信息等（可以考虑将其不作为服务使用）
    services.factory('personService',['$http', 'OssEndpoint',
	    function($http,OssEndpoint){
			var doRequest = function(data){
				var response = $http({
					method : 'POST'
					,url : $rootScope.getServiceName() + '/security/personInfo/query'
					,data:  data
				});	
				return response;
			};
			var doRequest1 = function(id){
				/*
				var response = $http({
					method : 'GET'
					,url : '/security/personInfo/delete'
				    ,params:  {'id':user.fid.value}
				});	
				*/
				var response = $.ajax({
		            type: "GET",
		            async : false,
		            url: $rootScope.getServiceName() + "/security/personInfo/delete",
		            data: {"id":id},// "{}",
		            contentType: "application/json; charset=utf-8",
		            dataType: "json",
//		            processData: false,
		            success: function (data,textStatus) {
		                // Play with returned data in JSON format
		            },
		            error: function (XMLHttpRequest, textStatus, errorThrown) {
		            }
		        });

				return response;
			};
			var doRequest2 = function(data){
				/*
				var response = $http({
					method : 'POST'
					,url : '/security/personInfo/save'
//				    ,data : {'username':'$scope.username','userlabel':'$scope.userlabe'}
		    		,data : data
				});	
				*/
				var response = $.ajax({
		            type: "POST",
		            async : false,
		            url: $rootScope.getServiceName() + "/security/personInfo/save",
		            data: JSON.stringify(data),// "{}",
		            contentType: "application/json; charset=utf-8",
		            dataType: "json",
//		            processData: false,
		            success: function (data) {
		                // Play with returned data in JSON format
		            },
		            error: function (msg) {
//		                alert(msg.responseText);
		            }
		        });
				
				return response;
			};

			return {
				query: function(data){
					return doRequest(data);
				},
				remove: function(id){
					return doRequest1(id);
				},
				save: function(data){
					return doRequest2(data);
				}
			};
		}
	])
	
	//组织信息管理服务
    services.factory('billSettingService',['$http', 'OssEndpoint',
	    function($http,OssEndpoint){
			var doRequest = function(data){
				var response = $http({
					method : 'POST'
					,url : $rootScope.getServiceName() + '/security/billSetting/query'
					,data:  data
				});	
				return response;
			};
			var doRequest1 = function(id){
				var response = $http({
					method : 'GET'
					,url : $rootScope.getServiceName() + '/security/billSetting/delete'
				    ,params:  {'id':id}
				});	
				return response;
			};
			var doRequest2 = function(data){
				/*
				var response = $http({
					method : 'POST'
					,url : '/security/systemXML/save'
//				    ,data : {'rolename':'$scope.rolename','rolelabel':'$scope.rolelabe'}
		    		,data : data
				});	
				*/
				/*
				data:要求为Object或String类型的参数，发送到服务器的数据。如果已经不是字符串
				，将自动转换为字符串格式。get请求中将附加在url后。防止这种自动转换
				，可以查看　　processData选项。对象必须为key/value格式
				，例如{foo1:"bar1",foo2:"bar2"}转换为&foo1=bar1&foo2=bar2。如果是数组
				，JQuery将自动为不同值对应同一个名称。
				例如{foo:["bar1","bar2"]}转换为&foo=bar1&foo=bar2。
				*/
				var response = $.ajax({
		            type: "POST",
		            async : false,
		            url: $rootScope.getServiceName() + "/security/billSetting/save",
		            data: JSON.stringify(data),// "{}",
		            contentType: "application/json; charset=utf-8",
		            dataType: "json",
//		            processData: false,
		            success: function (data) {
		                // Play with returned data in JSON format
		            },
		            error: function (msg) {
//		                alert(msg.responseText);
		            }
		        });
				
				
				return response;
			};
			return {
				query: function(data){
					return doRequest(data);
				},
				remove: function(id){
					return doRequest1(id);
				},
				save: function(data){
					return doRequest2(data);
				}
			};
		}
	])
	
	//用户应用列表信息管理服务
    services.factory('sysInfoOrgService',['$http','OssEndpoint',
	    function($http,OssEndpoint){
			var doRequest = function(data){
				var response = $http({
					method : 'POST'
					,url : $rootScope.getServiceName() + '/usercenter/sysInfoOrg/query'
					,data:  data
				});	
				return response;
			};
			var doRequest1 = function(id){
				var response = $http({
					method : 'GET'
					,url : $rootScope.getServiceName() + '/usercenter/sysInfoOrg/delete'
				    ,params:  {'id':id}
				});	
				return response;
			};
			var doRequest2 = function(data){
				/*
				var response = $http({
					method : 'POST'
					,url : '/security/sysInfoOrg/save'
//				    ,data : {'rolename':'$scope.rolename','rolelabel':'$scope.rolelabe'}
		    		,data : data
				});	
				*/
				/*
				data:要求为Object或String类型的参数，发送到服务器的数据。如果已经不是字符串
				，将自动转换为字符串格式。get请求中将附加在url后。防止这种自动转换
				，可以查看　　processData选项。对象必须为key/value格式
				，例如{foo1:"bar1",foo2:"bar2"}转换为&foo1=bar1&foo2=bar2。如果是数组
				，JQuery将自动为不同值对应同一个名称。
				例如{foo:["bar1","bar2"]}转换为&foo=bar1&foo=bar2。
				*/
				var response = $.ajax({
		            type: "POST",
		            async : false,
		            url: $rootScope.getServiceName() + "/usercenter/sysInfoOrg/save",
		            data: JSON.stringify(data),// "{}",
		            contentType: "application/json; charset=utf-8",
		            dataType: "json",
//		            processData: false,
		            success: function (data) {
		                // Play with returned data in JSON format
		            },
		            error: function (msg) {
//		                alert(msg.responseText);
		            }
		        });
				
				
				return response;
			};
			var doRequest3 = function(id){
				var response = $http({
					method : 'GET'
					,url : $rootScope.getServiceName() + '/usercenter/sysInfoOrg/copyList'
				    ,params:  {'id':id}
				});	
				return response;
			};
			var doRequest4 = function(ognID,sysID){
				var response = $http({
					method : 'GET'
					,url : $rootScope.getServiceName() + '/usercenter/sysInfoOrg/startUsing'
				    ,params:  {'ognID':ognID,'sysID':sysID}
				});	
				return response;
			};

			
			
			return {
				query: function(data){
					return doRequest(data);
				},
				remove: function(id){
					return doRequest1(id);
				},
				save: function(data){
					return doRequest2(data);
				},
				copyList: function(id){
					return doRequest3(id);
				}
				,
				startUsing: function(ognID,sysID){
					return doRequest4(ognID,sysID);
				}
			};
		}
	])

	services.factory('accessMarksService',['$http', 'OssEndpoint', function($http,OssEndpoint){
		var doRequest = function(){
			var response = $http({
				method : 'GET'
				,url : $rootScope.getServiceName() + '/security/accessMarks/query'
			});	
			return response;
		};
		var doRequest1 = function(accessMarks){
			var response = $http({
				method : 'GET'
				,url : $rootScope.getServiceName() + '/security/accessMarks/delete'
				,params:  {'sessionId':accessMarks.sessionId}
			});	
			return response;
		};
		var total = function () {
			return $http.get($rootScope.getServiceName() + '/security/accessMarks/total');
		};
		var list = function (page, size, remoteIp, remoteIpPlace, userAgent) {
	        return $http({
	            params: {
	                page: page
	                ,size: size
	                ,remoteIp: remoteIp
	                ,remoteIpPlace: remoteIpPlace
	                ,userAgent: userAgent
	            },
	            url: $rootScope.getServiceName() + '/security/accessMarks/list'
	        });
	    };
	    //获取图表数据
		var chartData = function () {
	//		return $http.get('/security/accessMarks/pie');
			var response = $http({
				method : 'GET'
	//			,asyn : false
				,url : $rootScope.getServiceName() + '/security/accessMarks/pie'
			});	
			return response;
		};
	
		return {
			accessMarksList: function(){
				return doRequest();
			}
			,accessMarksDelete: function(accessMarks){
				return doRequest1(accessMarks);
			}
			,total: function () {
	            return total();
	        }
			,list: function (page, size, remoteIp, remoteIpPlace, userAgent) {
	            return list(page, size, remoteIp, remoteIpPlace, userAgent);
	        }
			,chartData: function () {
	            return chartData();
	        }
		};
	}])
	
	//测试
    services.factory('dingtalkService',['$http',
	    function($http){
			
			var accessToken = function(data){
 		           
				var response = $http.jsonp("https://oapi.dingtalk.com/gettoken?callback=JSON_CALLBACK&corpid=ding0523f88efc07019c&corpsecret=VB4kW5vNdG4nBGAo8CaCGLmhv8sTFI4jSE9tkeHSFgnj6luG8RdBc1QLFnSpSsNf")
				.success(function (data,textStatus) {
				});
				
				
				return response;
			};
			

			return {
				getAccessToken: function(data){
					return accessToken(data);
				}
			};
		}
	])
	
	//单据计算服务
    services.factory('uServiceCenter',['OssEndpoint', function (OssEndpoint){
    	//define(['common','services'],function(common,costingUtilService){
    	
		var _self = this;

		//算税：（用于销售订单和采购订单和委外工单），也可以用于采购发票（令参数discountAmount=0）
		//参数：数量、单价、折扣率、整单折扣额、税种、税率（BigDecimal itemAmount,BigDecimal itemPrice,BigDecimal discountRate,BigDecimal discountAmount,int taxType,BigDecimal taxRate）
		//输出：未税金额、税额和加税合计
		this.taxCalculate = function (event){
			var itemAmount = event.itemAmount;
			var itemPrice = event.itemPrice;
			var discountRate = event.discountRate;
			var discountAmount = event.discountAmount;
			var taxType = event.taxType;
			var taxRate = event.taxRate;
			
			if (isNaN(itemAmount)) 
				itemAmount = 0;
			if (isNaN(itemPrice)) 
				itemPrice = 0;
			if (isNaN(discountRate)) 
				discountRate = 1;
			if (isNaN(discountAmount)) 
				discountAmount = 0;

			var orderAmount = common.accMul(common.accMul(itemAmount , itemPrice),discountRate);
			////////////////////////////////////////////////////////
			orderAmount = common.accSub(orderAmount,discountAmount);
			///////////////////////////////////////////////////////////////////

			var orderAmountOld = 0;
			var orderAmountTax = 0;
			//////////////////////////////////////////////////////////////////////////////////////////////////////////
			if (taxType == -1) {
				// -1.免税
				orderAmountOld = orderAmount;
				orderAmountTax = 0;
			}
			if (taxType == 0) {
				// 0.应税外加
				orderAmountOld = orderAmount;
				orderAmountTax = common.accMul(orderAmountOld , taxRate).toFixed(2);
			}
			if (taxType == 1) {
				// 1.应税内含
				orderAmountOld = common.accDiv(orderAmount , common.accAdd(1 , taxRate)).toFixed(2);
				orderAmountTax = common.accSub(orderAmount , orderAmountOld);
			}
			///////////////////////////////////////////////////////////////////////////////////////////////////////////

			//取两位小数
			orderAmount = parseFloat(orderAmount).toFixed(2);
			orderAmountOld = parseFloat(orderAmountOld).toFixed(2);
			orderAmountTax = parseFloat(orderAmountTax).toFixed(2);
			
			var orderAmountTotal = common.accAdd(orderAmountOld , orderAmountTax);
			
			var data = {};
			data.orderAmount = orderAmount;
			data.orderAmountOld = orderAmountOld;
			data.orderAmountTax = orderAmountTax;
			data.orderAmountTotal = orderAmountTotal;
			return data;
		};


		//这个可能没有什么用处（因为进货费用有发票，不能计入采购发票中，只是计算采购成本时有用）
		//算税：（用于采购进货、委外进货）
		//参数：数量、单价、折扣率、整单折扣额、税种、税率、进货费用分摊
		//输出：未税金额、税额和加税合计
		this.taxCalculateEx = function (event){
			var itemAmount = event.itemAmount;
			var itemPrice = event.itemPrice;
			var discountRate = event.discountRate;
			var discountAmount = event.discountAmount;
			var taxType = event.taxType;
			var taxRate = event.taxRate;
			
			var apportionAmount = event.apportionAmount;
			
			if (isNaN(itemAmount)) 
				itemAmount = 0;
			if (isNaN(itemPrice)) 
				itemPrice = 0;
			if (isNaN(discountRate)) 
				discountRate = 1;
			if (isNaN(discountAmount)) 
				discountAmount = 0;
			if (isNaN(apportionAmount)) 
				apportionAmount = 0;

			var orderAmount = common.accMul(common.accMul(itemAmount , itemPrice),discountRate);
			////////////////////////////////////////////////////////
			orderAmount = common.accSub(orderAmount,discountAmount);
			///////////////////////////////////////////////////////////////////
			
			orderAmount = common.accAdd(orderAmount,apportionAmount);

			var orderAmountOld = 0;
			var orderAmountTax = 0;
			//////////////////////////////////////////////////////////////////////////////////////////////////////////
			if (taxType == -1) {
				// -1.免税
				orderAmountOld = orderAmount;
				orderAmountTax = 0;
			}
			if (taxType == 0) {
				// 0.应税外加
				orderAmountOld = orderAmount;
				orderAmountTax = common.accMul(orderAmountOld , taxRate).toFixed(2);
			}
			if (taxType == 1) {
				// 1.应税内含
				orderAmountOld = common.accDiv(orderAmount , common.accAdd(1 , taxRate)).toFixed(2);
				orderAmountTax = common.accSub(orderAmount , orderAmountOld);
			}
			///////////////////////////////////////////////////////////////////////////////////////////////////////////

			//取两位小数
			orderAmount = parseFloat(orderAmount).toFixed(2);
			orderAmountOld = parseFloat(orderAmountOld).toFixed(2);
			orderAmountTax = parseFloat(orderAmountTax).toFixed(2);
			
			var orderAmountTotal = common.accAdd(orderAmountOld , orderAmountTax);
			
			var data = {};
			data.orderAmount = orderAmount;
			data.orderAmountOld = orderAmountOld;
			data.orderAmountTax = orderAmountTax;
			data.orderAmountTotal = orderAmountTotal;
			return data;
		};


		//订单主表变动
		this.orderMasterValueChanged = function (event){
//			console.log('event.column-->',event.column);
			//判断值改变是由手工输入，还是setValue函数设置
//			console.log('event.setted-->',event.setted);
//			console.log('event.source-->',event.source);

			
			if(event.column=="taxRate"){
				var dataMaster = event.source;
				var rowID = dataMaster.getID(event.rowIndex);
				var taxRate = dataMaster.getValue('taxRate',rowID);
				//判断是否有从表
				var slaveDatas = dataMaster.slaveDatas;
				if(slaveDatas.length>0){
					//存在从表,需要调用从表的数据打包函数
					//遍历从data
				    for(var i=0;i<slaveDatas.length;i++){
				    	var dataDetail = dataMaster.container[slaveDatas[i]];
						for(var j=0;j<dataDetail.getCount();j++){
					    	dataDetail.setValue('taxRate',taxRate,dataDetail.getID(j));
						}
				    }
				}
			}
			
			if(event.column=="taxType"){
				var dataMaster = event.source;
				var rowID = dataMaster.getID(event.rowIndex);
				var taxType = dataMaster.getValue('taxType',rowID);
				var taxTypeLabel = dataMaster.getValue('taxTypeLabel',rowID);
				//判断是否有从表
				var slaveDatas = dataMaster.slaveDatas;
				if(slaveDatas.length>0){
					//存在从表,需要调用从表的数据打包函数
					//遍历从data
				    for(var i=0;i<slaveDatas.length;i++){
				    	var dataDetail = dataMaster.container[slaveDatas[i]];
						for(var j=0;j<dataDetail.getCount();j++){
					    	dataDetail.setValue('taxType',taxType,dataDetail.getID(j));
					    	dataDetail.setValue('taxTypeLabel',taxTypeLabel,dataDetail.getID(j));
						}
				    }
				}
			}
			/*放到后台去做
			//计算整单折扣，分配整单折扣额到从表中
			if(event.column=="discountAmount"){
				var dataMaster = event.source;
				var rowID = dataMaster.getID(event.rowIndex);
				var taxType = dataMaster.getValue('taxType',rowID);
				var discountAmountMaster = dataMaster.getValue('discountAmount',rowID);
				if (isNaN(discountAmountMaster)) 
					discountAmountMaster = 0;
				var orderAmountMaster = dataMaster.getValue('orderAmount',rowID);
				var orderAmountTotalMaster = dataMaster.getValue('orderAmountTotal',rowID);

				//判断是否有从表
				var slaveDatas = dataMaster.slaveDatas;
				if(slaveDatas.length>0){
					//存在从表,需要调用从表的数据打包函数
					//遍历从data
				    for(var i=0;i<slaveDatas.length;i++){
				    	var dataDetail = dataMaster.container[slaveDatas[i]];
						//含税：按orderAmount比例分配
						if(taxType==1 || taxType==-1){
							for(var j=0;j<dataDetail.getCount();j++){
								var orderAmount = dataDetail.getValue('orderAmount',dataDetail.getID(j));
								var splitRate = common.accDiv(orderAmount,orderAmountMaster);
								var discountAmount = common.accMul(discountAmountMaster,splitRate).toFixed(2);
						    	dataDetail.setValue('discountAmount',discountAmount,dataDetail.getID(j));
							}
						}
					
						//不含税：按orderAmountTotal比例分配
						if(taxType==0){
							//外加税或者免税
							for(var j=0;j<dataDetail.getCount();j++){
								var orderAmountTotal = dataDetail.getValue('orderAmountTotal',dataDetail.getID(j));
								var splitRate = common.accDiv(orderAmountTotal,orderAmountTotalMaster);
								var discountAmount = common.accMul(discountAmountMaster,splitRate);
								var taxRate = dataDetail.getValue('taxRate',dataDetail.getID(j));
								discountAmount = common.accDiv(discountAmount,common.accAdd(1,taxRate)).toFixed(2);
						    	dataDetail.setValue('discountAmount',discountAmount,dataDetail.getID(j));
							}
						}
							
				    }

				}
			}
			*/
			
			if(event.column=='orderDate'){
				var dataMaster = event.source;
				var rowID = dataMaster.getID(event.rowIndex);
				var orderDate = dataMaster.getValue('orderDate',rowID);
				//判断是否有从表
				var slaveDatas = dataMaster.slaveDatas;
				if(slaveDatas.length>0){
					//存在从表,需要调用从表的数据打包函数
					//遍历从data
				    for(var i=0;i<slaveDatas.length;i++){
				    	var dataDetail = dataMaster.container[slaveDatas[i]];
						for(var j=0;j<dataDetail.getCount();j++){
					    	dataDetail.setValue('orderDate',orderDate,dataDetail.getID(j));
						}
				    }
				}
			}
			if(event.column=='factoryNo'){
				var dataMaster = event.source;
				var rowID = dataMaster.getID(event.rowIndex);
				var factoryID = dataMaster.getValue('factoryID',rowID);
				var factoryNo = dataMaster.getValue('factoryNo',rowID);
				var factoryName = dataMaster.getValue('factoryName',rowID);
				//判断是否有从表
				var slaveDatas = dataMaster.slaveDatas;
				if(slaveDatas.length>0){
					//存在从表,需要调用从表的数据打包函数
					//遍历从data
				    for(var i=0;i<slaveDatas.length;i++){
				    	var dataDetail = dataMaster.container[slaveDatas[i]];
						for(var j=0;j<dataDetail.getCount();j++){
					    	dataDetail.setValue('factoryID',factoryID,dataDetail.getID(j));
					    	dataDetail.setValue('factoryNo',factoryNo,dataDetail.getID(j));
					    	dataDetail.setValue('factoryName',factoryName,dataDetail.getID(j));
						}
				    }
				}
			}
			if(event.column=='employeeNo'){
				var dataMaster = event.source;
				var rowID = dataMaster.getID(event.rowIndex);
				var employeeNo = dataMaster.getValue('employeeNo',rowID);
				var employeeName = dataMaster.getValue('employeeName',rowID);
				//判断是否有从表
				var slaveDatas = dataMaster.slaveDatas;
				if(slaveDatas.length>0){
					//存在从表,需要调用从表的数据打包函数
					//遍历从data
				    for(var i=0;i<slaveDatas.length;i++){
				    	var dataDetail = dataMaster.container[slaveDatas[i]];
						for(var j=0;j<dataDetail.getCount();j++){
					    	dataDetail.setValue('employeeNo',employeeNo,dataDetail.getID(j));
					    	dataDetail.setValue('employeeName',employeeName,dataDetail.getID(j));
						}
				    }
				}
			}
			
		};

		//订单计算（采购订单、销售订单）
		this.orderCalculate = function (event){
			//计价
			if (event.column == "itemPrice" || event.column == "itemAmount" || event.column == "discountRate" || event.column == "discountAmount" || event.column == "taxType" || event.column == "taxRate") {
				// 计价数量或者单价改变时,金额和税额跟随改变

				var dataDetail = event.source;
				var rowID = dataDetail.getID(event.rowIndex);

				var itemAmount = parseFloat(dataDetail.getValue("itemAmount", rowID));// 订单数量
				var itemPrice = parseFloat(dataDetail.getValue("itemPrice", rowID));// 单价
				var discountRate = parseFloat(dataDetail.getValue("discountRate", rowID));// 折扣率
				var discountAmount = parseFloat(dataDetail.getValue("discountAmount", rowID));// 整单折扣（额）
				
				if (isNaN(itemAmount)) 
					itemAmount = 0;
				if (isNaN(itemPrice)) 
					itemPrice = 0;
				if (isNaN(discountRate)) 
					discountRate = 1;
				if (isNaN(discountAmount)) 
					discountAmount = 0;

				var taxType = parseInt(dataDetail.getValue("taxType", rowID)); // -1.免税;0.应税外加;1.应税内含
				var taxRate = parseFloat(dataDetail.getValue("taxRate",rowID));// 税率
				
				if (isNaN(taxType)) 
					taxType = 0;
				if (isNaN(taxRate)) 
					taxRate = 0;

				///////////////////////////////////////////////////////////////////////////////////////////////////////////
				var params = {};
				params.itemAmount = itemAmount;
				params.itemPrice = itemPrice;
				params.discountRate = discountRate;
				params.discountAmount = discountAmount;
				params.taxType = taxType;
				params.taxRate = taxRate;
				
				var data = _self.taxCalculate(params);
				
				var	orderAmount = 0;
				var orderAmountOld = 0;
				var orderAmountTax = 0;
				var orderAmountTotal = 0;
				
				orderAmount = data.orderAmount;
				orderAmountOld = data.orderAmountOld;
				orderAmountTax = data.orderAmountTax;
				orderAmountTotal = data.orderAmountTotal;
				///////////////////////////////////////////////////////////////////////////////////////////////////////////

				dataDetail.setValue("orderAmount", orderAmount, rowID);
				dataDetail.setValue("orderAmountTax", orderAmountTax, rowID);
				dataDetail.setValue("orderAmountOld", orderAmountOld, rowID);
				dataDetail.setValue("orderAmountTotal", orderAmountTotal, rowID);
			}	
			
			
			//改变主表汇总值
			//获取主data
			
			var dataMaster = event.source.masterData;
			if(dataMaster!=null){
				//更新主表的汇总值
				if(event.column=="freightAmount" 
					|| event.column=="discountAmount"
							|| event.column=="orderWeight"
								|| event.column=="pieceQuantity"
						){
					var sum = event.source.getSum(event.column);
					if (isNaN(sum)){sum = 0;} 
					dataMaster.setValue(event.column,sum,dataMaster.getCurrentID());
				}
				if(event.column=="itemAmount" 
						|| event.column=="orderAmount"
							|| event.column=="orderAmountOld"
								|| event.column=="orderAmountTax"
									|| event.column=="orderAmountTotal"
						){
					var sum = event.source.getSum(event.column);
					if (isNaN(sum)){sum = 0;} 
					dataMaster.setValue(event.column,sum,dataMaster.getCurrentID());
				}
			}
			
		};
		

		//订单计算（采购订单、销售订单）
		this.orderDetailAfterDelete = function (event){
			//获取主data
			var dataMaster = event.source.masterData;
//			console.log('主data-->',dataMaster);
			if(dataMaster!=null){
				var masterRowID = dataMaster.getCurrentID();
				//更新主表中子表记录数
				dataMaster.setValue('detailsCount', dataMaster.getValue('detailsCount', masterRowID) - 1, masterRowID);	
				
				//计算主表合计
				//数量
				var column="itemAmount";
				var sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//金额
				column="orderAmount";
				sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//未税金额
				column="orderAmountOld";
				sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//税额
				column="orderAmountTax";
				sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//加税合计
				column="orderAmountTotal";
				sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//件数
				column="pieceQuantity";
				sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//包装重量
				column="orderWeight";
				sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//运费
//				column="freightAmount";
//				sum = event.source.getSum(column);
//				dataMaster.setValue(column,sum,masterRowID);
				//其他费用
				column="discountAmount";
				sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
			}
		};
		
		//入出库单主表变动
		this.rkckMasterValueChanged = function (event){

			
			if(event.column=="taxRate"){
				var dataMaster = event.source;
				var rowID = dataMaster.getID(event.rowIndex);
				var taxRate = dataMaster.getValue('taxRate',rowID);
				//判断是否有从表
				var slaveDatas = dataMaster.slaveDatas;
				if(slaveDatas.length>0){
					//存在从表,需要调用从表的数据打包函数
					//遍历从data
				    for(var i=0;i<slaveDatas.length;i++){
				    	var dataDetail = dataMaster.container[slaveDatas[i]];
						for(var j=0;j<dataDetail.getCount();j++){
							dataDetail.setValue('taxRate',taxRate,dataDetail.getID(j));
						}
				    }
				}
			}
			
			if(event.column=="taxType"){
				var dataMaster = event.source;
				var rowID = dataMaster.getID(event.rowIndex);
				var taxType = dataMaster.getValue('taxType',rowID);
				var taxTypeLabel = dataMaster.getValue('taxTypeLabel',rowID);
				//判断是否有从表
				var slaveDatas = dataMaster.slaveDatas;
				if(slaveDatas.length>0){
					//存在从表,需要调用从表的数据打包函数
					//遍历从data
				    for(var i=0;i<slaveDatas.length;i++){
				    	var dataDetail = dataMaster.container[slaveDatas[i]];
						for(var j=0;j<dataDetail.getCount();j++){
					    	dataDetail.setValue('taxType',taxType,dataDetail.getID(j));
					    	dataDetail.setValue('taxTypeLabel',taxTypeLabel,dataDetail.getID(j));
						}
				    }
				}
			}
		};
		
		//出入库计算（入库单和出库单使用）
		this.rkckCalculate = function(event){
			
			///////////////////////////数量计算公式////////////////////////////////////
			//验退数量 = 到货数量 - 验收数量 - 报废数量 - 损耗数量
			//计价数量 = 验收数量 + 损耗数量
			///////////////////////////////////////////////////////////////////////////

			//借助质量检验的计算公式
			//this.qualityCalculate(event);
			///////////////////////////////////////////////////////////////////
			//到货数量
			if (event.column == "arriveAmount"){
				//alert("到货数量");
				var dataDetail = event.source;
				var rowID = dataDetail.getID(event.rowIndex);
				var arriveAmount = event.value;
				
				//合格数量（验收数量）
				dataDetail.setValue("itemAmount", arriveAmount, rowID);
				//报废数量
				dataDetail.setValue("wasterAmount", 0, rowID);
				//损耗数量
				dataDetail.setValue("ullageAmount", 0, rowID);
				//验退数量
				dataDetail.setValue("arriveAmountBack", 0, rowID);
				//计价数量
				dataDetail.setValue("priceAmount", arriveAmount, rowID);
			}

			//其他数量
			if (event.column == "itemAmount" || event.column == "wasterAmount" || event.column == "ullageAmount"){
				//alert("到货数量");
				var dataDetail = event.source;
				var rowID = dataDetail.getID(event.rowIndex);
				
				//计算
				//输入参数
				var arriveAmount = dataDetail.getValue("arriveAmount", rowID);// 到货数量
				var itemAmount = dataDetail.getValue("itemAmount", rowID);// 验收数量
				var wasterAmount = dataDetail.getValue("wasterAmount", rowID);// 废品数量
				var ullageAmount = dataDetail.getValue("ullageAmount", rowID);// 损耗数量
				var arriveAmountBack = dataDetail.getValue("arriveAmountBack", rowID);
				//输出结果
				//验退数量
				var arriveAmountBack = common.accSub(arriveAmount, itemAmount);
				arriveAmountBack = common.accSub(arriveAmountBack, wasterAmount);
				arriveAmountBack = common.accSub(arriveAmountBack, ullageAmount);
				dataDetail.setValue("arriveAmountBack", arriveAmountBack, rowID);
				//计价数量
//				console.log('rkckCalculate.itemAmount-->>',itemAmount);
//				console.log('rkckCalculate.ullageAmount-->>',ullageAmount);
				var priceAmount = common.accAdd(itemAmount, ullageAmount);
				dataDetail.setValue("priceAmount", priceAmount, rowID);
			}
			///////////////////////////////////////////////////////////////////
		
			/*
			if (event.column == "itemAmount"){
				//alert("验退数量");
				var dataDetail = event.source;
				var rowID = dataDetail.getID(event.rowIndex);
				
				//计算
				//输入参数
				var itemAmount = dataDetail.getValue("itemAmount", rowID);// 验收数量
				
				if (isNaN(itemAmount)) 
					itemAmount = 0;
				
				//输出结果
				/////////////////////////////////////////////////////////////////////////
//				dataDetail.setValue("arriveAmount", itemAmount, rowID);
//				dataDetail.setValue("priceAmount", itemAmount, rowID);
				
				///////////////////////////////////////////////////////////////
				var revOpay = dataDetail.getValue("revOpay", rowID); 
				direction = dataDetail.getValue("direction", rowID);
				if (revOpay == "I"){
					dataDetail.setValue("accountQuantityI", common.accMul(itemAmount, direction), rowID);
				}
				if (revOpay == "O"){
					dataDetail.setValue("accountQuantityO", common.accMul(itemAmount, direction), rowID);
				}
				if (revOpay == "-"){
					dataDetail.setValue("accountQuantityI", common.accMul(itemAmount, direction), rowID);
					dataDetail.setValue("accountQuantityO", common.accMul(itemAmount, direction), rowID);
				}
				///////////////////////////////////////////////////////////////////////
					
			}
		
			//计算件数
			
			///////////////////////////////////////////////////////////////
			if (event.column == "pieceQuantity" ) {
				var dataDetail = event.source;
				var rowID = dataDetail.getID(event.rowIndex);
		
				var revOpay = dataDetail.getValue("revOpay", rowID); 
				var direction = dataDetail.getValue("direction", rowID);
				var pieceQuantity = dataDetail.getValue("pieceQuantity", rowID);
				
				if (isNaN(direction)) 
					direction = 0;
				if (isNaN(pieceQuantity)) 
					pieceQuantity = 0;

				if (revOpay == "I"){
					dataDetail.setValue("pieceQuantityI", common.accMul(pieceQuantity, direction), rowID);
				}
				if (revOpay == "O"){
					dataDetail.setValue("pieceQuantityO", common.accMul(pieceQuantity, direction), rowID);
				}
				if (revOpay == "-"){
					dataDetail.setValue("pieceQuantityI", common.accMul(pieceQuantity, direction), rowID);
					dataDetail.setValue("pieceQuantityO", common.accMul(pieceQuantity, direction), rowID);
				}
			}	
			///////////////////////////////////////////////////////////////////////
			*/
			
			//计价
			if (event.column == "itemPrice" || event.column == "priceAmount" || event.column == "discountRate" || event.column == "discountAmount" || event.column == "taxType" || event.column == "taxRate") {
				// 计价数量或者单价改变时,金额和税额跟随改变

				var dataDetail = event.source;
				var rowID = dataDetail.getID(event.rowIndex);

				//////////////////////////////////////////////////////////////////////////////////
				var itemAmount = parseFloat(dataDetail.getValue("priceAmount", rowID));// 计价数量
				//////////////////////////////////////////////////////////////////////////////////
				
				var itemPrice = parseFloat(dataDetail.getValue("itemPrice", rowID));// 单价
				var discountRate = parseFloat(dataDetail.getValue("discountRate", rowID));// 折扣率
				var discountAmount = parseFloat(dataDetail.getValue("discountAmount", rowID));// 整单折扣（额）
				
				if (isNaN(itemAmount)) 
					itemAmount = 0;
				if (isNaN(itemPrice)) 
					itemPrice = 0;
				if (isNaN(discountRate)) 
					discountRate = 1;
				if (isNaN(discountAmount)) 
					discountAmount = 0;

				var taxType = parseInt(dataDetail.getValue("taxType", rowID)); // -1.免税;0.应税外加;1.应税内含
				var taxRate = parseFloat(dataDetail.getValue("taxRate",rowID));// 税率
				
				if (isNaN(taxType)) 
					taxType = 0;
				if (isNaN(taxRate)) 
					taxRate = 0;

				///////////////////////////////////////////////////////////////////////////////////////////////////////////
				var params = {};
				params.itemAmount = itemAmount;
				params.itemPrice = itemPrice;
				params.discountRate = discountRate;
				params.discountAmount = discountAmount;
				params.taxType = taxType;
				params.taxRate = taxRate;
				
				var data = _self.taxCalculate(params);
				
				var	orderAmount = 0;
				var orderAmountOld = 0;
				var orderAmountTax = 0;
				var orderAmountTotal = 0;
				
				orderAmount = data.orderAmount;
				orderAmountOld = data.orderAmountOld;
				orderAmountTax = data.orderAmountTax;
				orderAmountTotal = data.orderAmountTotal;
				///////////////////////////////////////////////////////////////////////////////////////////////////////////

				dataDetail.setValue("orderAmount", orderAmount, rowID);
				dataDetail.setValue("orderAmountTax", orderAmountTax, rowID);
				dataDetail.setValue("orderAmountOld", orderAmountOld, rowID);
				dataDetail.setValue("orderAmountTotal", orderAmountTotal, rowID);
			}	
		
			//改变主表汇总值
			//获取主data
			var dataMaster = event.source.masterData;
//			console.log('主data-->',dataMaster);
			if(dataMaster!=null){
				//更新主表的汇总值
				if(event.column=="discountAmount" 
					|| event.column=="apportionAmount"
							|| event.column=="orderWeight"
								|| event.column=="pieceQuantity"
						){
					var sum = event.source.getSum(event.column);
					if (isNaN(sum)){sum = 0;} 
					dataMaster.setValue(event.column,sum,dataMaster.getCurrentID());
				}
			}

			
			//计算有效期至
			if(event.column=='produceDate'){
				var dataDetail = event.source;
				var rowID = dataDetail.getID(event.rowIndex);
				var produceDate = dataDetail.getValue('produceDate',rowID);
				if(produceDate!=null && produceDate!=''){
//					var d = justep.Date.fromString(produceDate,justep.Date.STANDART_FORMAT_SHOT);//'yyyy-MM-dd'//justep.Date.STANDART_FORMAT_SHOT
					var d = produceDate;//'yyyy-MM-dd'
					//alert('生产日期-->'+produceDate+'-->'+d.toString());
					//获取有效天数
					var validDays = parseInt(dataDetail.getValue('validDays',rowID));
			//		alert('有效天数-->'+validDays);
//					var validDate = justep.Date.increase(d,validDays,'d');
					var validDate = common.getNewDay(d,validDays);
					dataDetail.setValue('validDate',validDate,rowID);
					//获取复检天数
					/*
					var checkoutAgainDays = parseInt(dataDetail.getValue('checkoutAgainDays',rowID));
//					var checkoutAgainDate = justep.Date.decrease(validDate,checkoutAgainDays,'d');
					var checkoutAgainDate = common.getNewDay(validDate,-checkoutAgainDays);
//					dataDetail.setValue('checkoutAgainDate',justep.Date.toString(checkoutAgainDate,justep.Date.STANDART_FORMAT_SHOT),rowID);
					dataDetail.setValue('checkoutAgainDate',checkoutAgainDate,rowID);
					*/
				}
			}
			if(event.column=='validDate'){
				var dataDetail = event.source;
				var rowID = dataDetail.getID(event.rowIndex);
				var validDate = dataDetail.getValue('validDate',rowID);
				if(validDate!=null && validDate!=''){
					var d = validDate;//'yyyy-MM-dd'
					//获取复检天数
					var checkoutAgainDays = parseInt(dataDetail.getValue('checkoutAgainDays',rowID));
					var checkoutAgainDate = common.getNewDay(validDate,-checkoutAgainDays);
					dataDetail.setValue('checkoutAgainDate',checkoutAgainDate,rowID);
				}
			}
			
			//处理质量检验
			/*
			if(event.column=='qualityType'){
				var dataDetail = event.source;
				var rowID = dataDetail.getID(event.rowIndex);
				var billType = dataDetail.getValue("billType", rowID);
				var qualityType = dataDetail.getValue('qualityType',rowID);
				if(qualityType==0){
					//免检
					dataDetail.setValue('qualityStatus',2,rowID);
					dataDetail.setValue('qualityStatusLabel','2:合格',rowID);
				}else{
					//非免检
					var billType = dataDetail.getValue('billType',rowID);
					if(billType=='XSRK' || billType=='CGRK' || billType=='WWRK' || billType=='SCRK' || billType=='GYRK' || billType=='GYZY'){
						dataDetail.setValue('qualityStatus',1,rowID);
						dataDetail.setValue('qualityStatusLabel','1:待验',rowID);
					}else{
						dataDetail.setValue('qualityStatus',2,rowID);
						dataDetail.setValue('qualityStatusLabel','2:合格',rowID);
					}
				}
			}
			*/
		
		};

		//出入库计算（入库单和出库单使用）
		this.rkckDetailAfterDelete = function (event){
			//获取主data
			var dataMaster = event.source.masterData;
//			console.log('主data-->',dataMaster);
			if(dataMaster!=null){
				var masterRowID = dataMaster.getCurrentID();
				//更新主表中子表记录数
				dataMaster.setValue('detailsCount', dataMaster.getValue('detailsCount', masterRowID) - 1, masterRowID);	
				
				//计算主表合计
				//数量
				var column="itemAmount";
				var sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//金额
				column="orderAmount";
				sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//未税金额
				column="orderAmountOld";
				sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//税额
				column="orderAmountTax";
				sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//加税合计
				column="orderAmountTotal";
				sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//件数
				column="pieceQuantity";
				sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//包装重量
				column="orderWeight";
				sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//运费
				column="discountAmount";
				sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//其他费用
				column="apportionAmount";
				sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//扣款金额
			}
		};
		
		//检验单计算
		this.qualityCalculate = function (event){
			
			///////////////////////////数量计算公式////////////////////////////////////
			//验退数量 = 到货数量 - 验收数量 - 报废数量 - 损耗数量
			//计价数量 = 验收数量 + 损耗数量
			///////////////////////////////////////////////////////////////////////////

			//到货数量
			if (event.column == "arriveAmount"){
				//alert("到货数量");
				var dataDetail = event.source;
				var rowID = dataDetail.getID(event.rowIndex);
				var arriveAmount = event.value;
				
				//合格数量（验收数量）
				dataDetail.setValue("itemAmount", arriveAmount, rowID);
				//报废数量
				dataDetail.setValue("wasterAmount", 0, rowID);
				//损耗数量
				dataDetail.setValue("ullageAmount", 0, rowID);
				//验退数量
				dataDetail.setValue("arriveAmountBack", 0, rowID);
				//计价数量
				dataDetail.setValue("priceAmount", arriveAmount, rowID);
			}

			//其他数量
			if (event.column == "itemAmount" || event.column == "wasterAmount" || event.column == "ullageAmount"){
				//alert("到货数量");
				var dataDetail = event.source;
				var rowID = dataDetail.getID(event.rowIndex);
				
				//计算
				//输入参数
				var arriveAmount = dataDetail.getValue("arriveAmount", rowID);// 到货数量
				var itemAmount = dataDetail.getValue("itemAmount", rowID);// 验收数量
				var wasterAmount = dataDetail.getValue("wasterAmount", rowID);// 废品数量
				var ullageAmount = dataDetail.getValue("ullageAmount", rowID);// 损耗数量
				var arriveAmountBack = dataDetail.getValue("arriveAmountBack", rowID);
				//输出结果
				//验退数量
				var arriveAmountBack = common.accSub(arriveAmount, itemAmount);
				arriveAmountBack = common.accSub(arriveAmountBack, wasterAmount);
				arriveAmountBack = common.accSub(arriveAmountBack, ullageAmount);
				dataDetail.setValue("arriveAmountBack", arriveAmountBack, rowID);
				//计价数量
				var priceAmount = common.accAdd(itemAmount,ullageAmount);
				dataDetail.setValue("priceAmount", priceAmount, rowID);
			}
			
		};

		this.quantityMasterBeforeSave = function (event){
			var dataMaster = event.source;
			var rowID = dataMaster.getCurrentID();
			var originNo = dataMaster.getValue('originNo',rowID);
			if(originNo==null || originNo==undefined || originNo==''){
				event.cancel = true;
				alert('单号不能为空！');
			}
		};
		
		//应收应付主表变动
		this.invoiceMasterValueChanged = function (event){
			
			if (event.column == "direction" || event.column == "orderAmountOld" 
				|| event.column == "orderAmountTax" || event.column == "orderAmountTotal" 
					) {
				var dataMaster = event.source;
				var rowID = dataMaster.getID(event.rowIndex);
				
				var direction = dataMaster.getValue("direction",rowID);
				var orderAmountOld = dataMaster.getValue("orderAmountOld",rowID);
				var orderAmountTax = dataMaster.getValue("orderAmountTax",rowID);
				var orderAmountTotal = dataMaster.getValue("orderAmountTotal",rowID);
				
				var accountAmountOld = common.accMul(orderAmountOld, direction);
				var accountAmountTax = common.accMul(orderAmountTax, direction);
				var accountAmountTotal = common.accMul(orderAmountTotal, direction);
				dataMaster.setValue("accountAmountOld", accountAmountOld, rowID);
				dataMaster.setValue("accountAmountTax", accountAmountTax, rowID);
				dataMaster.setValue("accountAmountTotal", accountAmountTotal, rowID);
				
				dataMaster.setValue("pendingAmount", orderAmountTotal, rowID);

			}
			
			if(event.column=='orderDate'){
				var rowID = event.source.getID(event.rowIndex);
				var orderDate = event.source.getValue('orderDate',rowID);
//				var dataDetail = Model.dataDetail;
				//从表
				var slaveDatas = event.source.slaveDatas;
				var dataDetail = event.source.container[slaveDatas[0]];
				if(dataDetail){
					for(var i=0;i<dataDetail.getCount();i++){
						dataDetail.setValue('orderDate',orderDate,dataDetail.getID(i));
					}
					
				}
			}
			if(event.column=='employeeNo'){
				var rowID = event.source.getID(event.rowIndex);
				var employeeNo = event.source.getValue('employeeNo',rowID);
				var employeeName = event.source.getValue('employeeName',rowID);
//				var dataDetail = Model.dataDetail;
				//从表
				var slaveDatas = event.source.slaveDatas;
				var dataDetail = event.source.container[slaveDatas[0]];
				if(dataDetail){
					for(var i=0;i<dataDetail.getCount();i++){
						dataDetail.setValue('employeeNo',employeeNo,dataDetail.getID(i));
						dataDetail.setValue('employeeName',employeeName,dataDetail.getID(i));
					}
					
				}
			}
			
			if(event.column=='dealObject'){
				var rowID = event.source.getID(event.rowIndex);
				var dealObject = event.source.getValue('dealObject',rowID);
				var dealObjectLabel = event.source.getValue('dealObjectLabel',rowID);
				
				//从表
				var slaveDatas = event.source.slaveDatas;
				var dataDetail = event.source.container[slaveDatas[0]];
				if(dataDetail){
					for(var i=0;i<dataDetail.getCount();i++){
						dataDetail.setValue('dealObject',dealObject,dataDetail.getID(i));
						dataDetail.setValue('dealObjectLabel',dealObjectLabel,dataDetail.getID(i));
					}
					
				}
			}
			
			if(event.column=='customerNo'){
				var rowID = event.source.getID(event.rowIndex);
				var customerID = event.source.getValue('customerID',rowID);
				var customerNo = event.source.getValue('customerNo',rowID);
				var shortName = event.source.getValue('shortName',rowID);
				var customerName = event.source.getValue('customerName',rowID);
				
				var isMember = event.source.getValue('isMember',rowID);
				var memberNo = event.source.getValue('memberNo',rowID);
				
				//从表
				var slaveDatas = event.source.slaveDatas;
				var dataDetail = event.source.container[slaveDatas[0]];
				if(dataDetail){
					for(var i=0;i<dataDetail.getCount();i++){
						dataDetail.setValue('customerID',customerID,dataDetail.getID(i));
						dataDetail.setValue('customerNo',customerNo,dataDetail.getID(i));
						dataDetail.setValue('shortName',shortName,dataDetail.getID(i));
						dataDetail.setValue('customerName',customerName,dataDetail.getID(i));
						
						dataDetail.setValue('isMember',isMember,dataDetail.getID(i));
						dataDetail.setValue('memberNo',memberNo,dataDetail.getID(i));
					}
					
				}
			}
			
			
			if(event.column=='fPhone'){
				var rowID = event.source.getID(event.rowIndex);
				var fPhone = event.source.getValue('fPhone',rowID);
//				var dataDetail = Model.dataDetail;
				//从表
				var slaveDatas = event.source.slaveDatas;
				var dataDetail = event.source.container[slaveDatas[0]];
				if(dataDetail){
					for(var i=0;i<dataDetail.getCount();i++){
						dataDetail.setValue('fPhone',fPhone,dataDetail.getID(i));
					}
					
				}
			}

			
			if (event.column == "periodNo" || event.column == "orderDate") {
				var dataMaster = event.source;
				var rowID =  dataMaster.getID(event.rowIndex);
				var periodStatus = dataMaster.getValue("periodStatus", rowID);
				var periodNo = dataMaster.getValue("periodNo", rowID);
				var orderDate = dataMaster.getValue("orderDate", rowID);
				if(periodStatus=="Y" && periodNo!=null && periodNo!="" && orderDate!=null && orderDate!=""){
					if(periodValid(periodNo,orderDate)==false){
						dataMaster.setValue("orderDate",null,rowID);
					}
				}
			}
			
		};

		//发票计算（采购发票、销售发票）
		this.invoiceCalculate = function (event){
			//计价
			if (event.column == "itemPrice" || event.column == "itemAmount" || event.column == "discountRate" || event.column == "discountAmount" || event.column == "taxType" || event.column == "taxRate") {
				// 计价数量或者单价改变时,金额和税额跟随改变

				var dataDetail = event.source;
				var rowID = dataDetail.getID(event.rowIndex);

				var itemAmount = parseFloat(dataDetail.getValue("itemAmount", rowID));// 订单数量
				var itemPrice = parseFloat(dataDetail.getValue("itemPrice", rowID));// 单价
				var discountRate = parseFloat(dataDetail.getValue("discountRate", rowID));// 折扣率
				var discountAmount = parseFloat(dataDetail.getValue("discountAmount", rowID));// 整单折扣（额）
				
				if (isNaN(itemAmount)) 
					itemAmount = 0;
				if (isNaN(itemPrice)) 
					itemPrice = 0;
				if (isNaN(discountRate)) 
					discountRate = 1;
				if (isNaN(discountAmount)) 
					discountAmount = 0;

				var taxType = parseInt(dataDetail.getValue("taxType", rowID)); // -1.免税;0.应税外加;1.应税内含
				var taxRate = parseFloat(dataDetail.getValue("taxRate",rowID));// 税率
				
				if (isNaN(taxType)) 
					taxType = 0;
				if (isNaN(taxRate)) 
					taxRate = 0;

				///////////////////////////////////////////////////////////////////////////////////////////////////////////
				var params = {};
				params.itemAmount = itemAmount;
				params.itemPrice = itemPrice;
				params.discountRate = discountRate;
				params.discountAmount = discountAmount;
				params.taxType = taxType;
				params.taxRate = taxRate;
				
				var data = _self.taxCalculate(params);
				
				var	orderAmount = 0;
				var orderAmountOld = 0;
				var orderAmountTax = 0;
				var orderAmountTotal = 0;
				
				orderAmount = data.orderAmount;
				orderAmountOld = data.orderAmountOld;
				orderAmountTax = data.orderAmountTax;
				orderAmountTotal = data.orderAmountTotal;
				///////////////////////////////////////////////////////////////////////////////////////////////////////////

				dataDetail.setValue("orderAmount", orderAmount, rowID);
				dataDetail.setValue("orderAmountTax", orderAmountTax, rowID);
				dataDetail.setValue("orderAmountOld", orderAmountOld, rowID);
				dataDetail.setValue("orderAmountTotal", orderAmountTotal, rowID);
			}	

			//改变主表汇总值
			//获取主data
			var dataMaster = event.source.masterData;
//			console.log('主data-->',dataMaster);
			if(dataMaster!=null){
				//更新主表的汇总值
				if(event.column=="itemAmount" 
					|| event.column=="orderAmount"
						|| event.column=="orderAmountOld"
							|| event.column=="orderAmountTax"
								|| event.column=="orderAmountTotal"
					){
					var sum = event.source.getSum(event.column);
					if (isNaN(sum)){sum = 0;} 
					dataMaster.setValue(event.column,sum,dataMaster.getCurrentID());
				}
				
			}
			
		};

		//发票明细删除之后（采购发票、销售发票）
		this.invoiceDetailAfterDelete = function (event){
			//获取主data
			var dataMaster = event.source.masterData;
//			console.log('主data-->',dataMaster);
			if(dataMaster!=null){
				var masterRowID = dataMaster.getCurrentID();
				//更新主表中子表记录数
				dataMaster.setValue('detailsCount', dataMaster.getValue('detailsCount', masterRowID) - 1, masterRowID);	
				
				//计算主表合计
				//数量
				var column="itemAmount";
				var sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//金额
				column="orderAmount";
				sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//扣款金额
				//未税金额
				column="orderAmountOld";
				sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//税额
				column="orderAmountTax";
				sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
				//加税合计
				column="orderAmountTotal";
				sum = event.source.getSum(column);
				dataMaster.setValue(column,sum,masterRowID);
			}
		};
		
		//实收实付主表（收款单、预收款单、收款核销单、付款单、预付款单、付款核销单）
		this.skfkMasterValueChanged = function (event){
//			console.log(event);
			//从表
			var slaveDatas = event.source.slaveDatas;
			var dataDetail = event.source.container[slaveDatas[0]];
			if(dataDetail){
				
				if(event.column=='orderDate'){
					var rowID = event.source.getID(event.rowIndex);
					var orderDate = event.source.getValue('orderDate',rowID);
					for(var i=0;i<dataDetail.getCount();i++){
						dataDetail.setValue('orderDate',orderDate,dataDetail.getID(i));
					}
				}
				if(event.column=='employeeNo'){
					var rowID = event.source.getID(event.rowIndex);
					var employeeNo = event.source.getValue('employeeNo',rowID);
					var employeeName = event.source.getValue('employeeName',rowID);
					for(var i=0;i<dataDetail.getCount();i++){
						dataDetail.setValue('employeeNo',employeeNo,dataDetail.getID(i));
						dataDetail.setValue('employeeName',employeeName,dataDetail.getID(i));
					}
				}
				if(event.column=='dealObject'){
					var rowID = event.source.getID(event.rowIndex);
					var dealObject = event.source.getValue('dealObject',rowID);
					var dealObjectLabel = event.source.getValue('dealObjectLabel',rowID);
					
					for(var i=0;i<dataDetail.getCount();i++){
						dataDetail.setValue('dealObject',dealObject,dataDetail.getID(i));
						dataDetail.setValue('dealObjectLabel',dealObjectLabel,dataDetail.getID(i));
					}
				}
				if(event.column=='customerNo'){
					var rowID = event.source.getID(event.rowIndex);
					var customerID = event.source.getValue('customerID',rowID);
					var customerNo = event.source.getValue('customerNo',rowID);
					var shortName = event.source.getValue('shortName',rowID);
					var customerName = event.source.getValue('customerName',rowID);
					
					var isMember = event.source.getValue('isMember',rowID);
					var memberNo = event.source.getValue('memberNo',rowID);
					
					for(var i=0;i<dataDetail.getCount();i++){
						dataDetail.setValue('customerID',customerID,dataDetail.getID(i));
						dataDetail.setValue('customerNo',customerNo,dataDetail.getID(i));
						dataDetail.setValue('shortName',shortName,dataDetail.getID(i));
						dataDetail.setValue('customerName',customerName,dataDetail.getID(i));
						
						dataDetail.setValue('isMember',isMember,dataDetail.getID(i));
						dataDetail.setValue('memberNo',memberNo,dataDetail.getID(i));
					}
				}
			}

			
			if (event.column == "periodNo" || event.column == "orderDate") {
				var dataMaster = event.source;
				var rowID =  dataMaster.getID(event.rowIndex);
				var periodStatus = dataMaster.getValue("periodStatus", rowID);
				var periodNo = dataMaster.getValue("periodNo", rowID);
				var orderDate = dataMaster.getValue("orderDate", rowID);
				if(periodStatus=="Y" && periodNo!=null && periodNo!="" && orderDate!=null && orderDate!=""){
					if(periodValid(periodNo,orderDate)==false){
						dataMaster.setValue("orderDate",null,rowID);
					}
				}
			}
			
			
			//计算实收金额
			/*
			if (event.column == "orderAmountCleared"  || event.column == "discountCash" || event.column == "direction") {
				var dataMaster = event.source;
				var rowID =  dataMaster.getID(event.rowIndex);
				var orderAmountCleared = dataMaster.getValue("orderAmountCleared", rowID);// 实收金额
				var discountCash = dataMaster.getValue("discountCash", rowID);// 折扣金额
				var orderAmount = common.accSub(orderAmountCleared , discountCash) ;// 实收金额=核销金额 - 折扣金额
				dataMaster.setValue('orderAmount', orderAmount, rowID);
			}
			*/
			
			//计算单据金额和帐金额
			if (event.column == "orderAmount"  || event.column == "discountCash" || event.column == "direction") {
				var dataMaster = event.source;
				var rowID =  dataMaster.getID(event.rowIndex);
				var orderAmount = dataMaster.getValue("orderAmount", rowID);// 实收金额
				if(orderAmount==null || isNaN(orderAmount)){orderAmount=0;}
				var discountCash = dataMaster.getValue("discountCash", rowID);// 折扣金额
				var orderAmountTotal = common.accAdd(orderAmount , discountCash) ;// 单据金额 - 折扣金额
//				orderAmount = orderAmount.toFixed(2);//报错
//				orderAmount = parseFloat(orderAmount).toFixed(2);//报错
				//计算单据金额
				dataMaster.setValue('orderAmountTotal', orderAmountTotal, rowID);
				dataMaster.setValue('pendingAmount', orderAmount, rowID);
				
				//计算帐实收
				var direction = dataMaster.getValue("direction", rowID);//收款单和收款退回单
				var accountClearActual = common.accMul(orderAmount, direction);
				var accountAmountTotal = common.accMul(orderAmountTotal, direction);
				dataMaster.setValue('accountAmountTotal', accountAmountTotal, rowID);	// 折扣金额
				
				dataMaster.setValue('accountClearActual', accountClearActual, rowID);	// 实收金额
			}
			
		};

		this.skfkMasterBeforeSave = function (event){
			/*
			//主表
			var dataMaster = event.source;
			var rowID = dataMaster.getCurrentID();
			var billType = dataMaster.getValue('billType',rowID);
			
			//从表
			var slaveDatas = dataMaster.slaveDatas;
			var dataDetail = dataMaster.container[slaveDatas[0]];
			var rowCount = dataDetail.getCount();
			
			if((billType=='YSKD' || billType=='YFKD') && rowCount<=0){
				return;
			}

			//主表单据金额
			var clearAmountTotal = dataMaster.getValue('clearAmountTotal',rowID);
			//从表核销金额汇总
			var sum = dataDetail.getSum('clearAmount');
			
			//如果单据金额不等于核销金额，则不能保存
			if (sum!=clearAmountTotal){
				event.cancel = true;
				alert('单据金额不等于核销金额，无法保存！');
//				systemService.dialogMsg('单据金额不等于核销金额，无法保存！');
				return;
			}
			*/
			
			//主表
			var dataMaster = event.source;
			var rowID = dataMaster.getCurrentID();
			var billType = dataMaster.getValue('billType',rowID);
			
			if((billType=='SKDJ' || billType=='FKDJ' || billType=='STDJ' || billType=='FTDJ')){
				var orderAmountCleared = dataMaster.getValue('orderAmountCleared',rowID);
				var orderAmountTotal = dataMaster.getValue('orderAmountTotal',rowID);
				//如果单据金额不等于核销金额，则不能保存
				if (orderAmountTotal!=orderAmountCleared){
					event.cancel = true;
					alert('单据金额不等于核销金额，无法保存！');
//					systemService.dialogMsg('单据金额不等于核销金额，无法保存！');
					return;
				}
			}
			
		};

		//收付款明细1删除之后（收款单、预收款单、收款核销单、付款单、预付款单、付款核销单）
		this.skfkDetailAfterDelete = function (event){
			//获取主data
			var dataMaster = event.source.masterData;
//			console.log('主data-->',dataMaster);
			if(dataMaster!=null){
				var masterRowID = dataMaster.getCurrentID();
				//计算主表合计
				//数量
				var sum = event.source.getSum('orderAmountCleared');
				dataMaster.setValue('orderAmountCleared',sum,masterRowID);
				//数量
				var sum = event.source.getSum('discountCash');
				dataMaster.setValue('discountCash',sum,masterRowID);
			}
		};

		//实收实付子表（收款单、预收款单、收款核销单、付款单、预付款单、付款核销单）
		this.skfkDetailValueChanged = function (event){
			//计算单据金额和帐金额
			if (event.column == "orderAmountCleared"|| event.column == "discountCash" || event.column == "direction") {
				var dataDetail = event.source;
				var rowID =  dataDetail.getID(event.rowIndex);
				var orderAmountCleared = dataDetail.getValue("orderAmountCleared", rowID);// 核销金额
				var discountCash = dataDetail.getValue("discountCash", rowID);// 折扣金额
				var direction = dataDetail.getValue("direction", rowID);//收款单和收款退回单

				var accountAmountCleared = common.accMul(orderAmountCleared, direction);
				dataDetail.setValue('accountClearPayable', accountAmountCleared, rowID);
				

				//根据收支类型进行赋值
				var origin = dataDetail.getValue("origin", rowID);
				if(origin == 'XSFP' || origin == 'QTYS' || origin == 'CGFP' || origin == 'QTYF'){
					//应收应付
					var accountDiscountCash = -discountCash;
					dataDetail.setValue('accountDiscountCash', accountDiscountCash, rowID);	// 折扣金额
				}
			}
			//设置主表（核销金额）
			if (event.column == "orderAmountCleared"|| event.column == "discountCash") {
				//改变主表汇总值
				//获取主data
				var dataMaster = event.source.masterData;
	//			console.log('主data-->',dataMaster);
				if(dataMaster!=null){
					//更新主表的汇总值
					var sum = event.source.getSum(event.column);
					if (isNaN(sum)){sum = 0;} 
					dataMaster.setValue(event.column,sum,dataMaster.getCurrentID());
				}
			}
			
		};

		
		//获取星期
		this.getWeekOfDate = function(dDate){
			var dataWeek = [
					{value:0,label:'日'}
					,{value:1,label:'一'}
					,{value:2,label:'二'}
					,{value:3,label:'三'}
					,{value:4,label:'四'}
					,{value:5,label:'五'}
					,{value:6,label:'六'}
					];
			var day = new Date(dDate).getDay();
//			for(var d in dataWeek){
//				console.log('d-->',d);
//				
//			}
			for(var i=0;i<dataWeek.length;i++){
//				console.log('day-->',dataWeek[i].label);
				if(dataWeek[i].value==day){
					return dataWeek[i].label;
				}
			}
			
			return null;
		};
		
		
		
		
		return{
			taxCalculate:function(event){
				return _self.taxCalculate(event);
			},
			rkckMasterValueChanged:function(event){
				return _self.rkckMasterValueChanged(event);
			},
			orderMasterValueChanged:function(event){
				return _self.orderMasterValueChanged(event);
			},
			rkckCalculate:function(event){
				return _self.rkckCalculate(event);
			},
			rkckDetailAfterDelete:function(event){
				return _self.rkckDetailAfterDelete(event);
			},
    		orderCalculate:function(event){
				return _self.orderCalculate(event);
			},
			orderDetailAfterDelete:function(event){
				return _self.orderDetailAfterDelete(event);
			},
			qualityCalculate:function(event){
				return _self.qualityCalculate(event);
			},
			quantityMasterBeforeSave:function(event){
				return _self.quantityMasterBeforeSave(event);
			},
			invoiceMasterValueChanged:function(event){
				return _self.invoiceMasterValueChanged(event);
			},
    		invoiceCalculate:function(event){
				return _self.invoiceCalculate(event);
			},
			invoiceDetailAfterDelete:function(event){
				return _self.invoiceDetailAfterDelete(event);
			},
			skfkMasterValueChanged:function(event){
				return _self.skfkMasterValueChanged(event);
			},
			skfkDetailValueChanged:function(event){
				return _self.skfkDetailValueChanged(event);
			},
			skfkMasterBeforeSave:function(event){
				return _self.skfkMasterBeforeSave(event);
			},
			skfkDetailAfterDelete:function(event){
				return _self.skfkDetailAfterDelete(event);
			},
			getWeekOfDate:function(event){
				return _self.getWeekOfDate(event);
			}
		}
		
    }])
	//拦截器
    services.factory('TokenInterceptor', function ($rootScope,$q, $window) {
        return {
            request: function (config) {
                config.headers = config.headers || {};
//                if ($window.localStorage.access_token) {
//                    config.headers.auth_token = $window.localStorage.access_token;
//                }
//                console.log('request.config-->',config);
                return config;
            },
            requestError: function (config) {
//                console.log('requestError.config-->',config);
                return config;
            },
    		/*
            response: function (response) {
                console.log('response.response-->',response);
//    			return response || $q.when(response);
                return $q.reject(response);
            },
            */
     		responseError: function (response) {
//                console.log('responseError.response-->',response);
                return $q.reject(response);
            }    
        };
    });

    services.controller("dialogMsgCtrl", ['$scope','$uibModalInstance','options',function f($scope,$uibModalInstance,options){
		
    	var Model = this;
    	
    	$uibModalInstance.opened.then(function(){
    		$scope.okText = '确定';
    		$scope.cancelText = '取消';
        	
    		var defaultConf = new Object();
    		defaultConf.title = '云逸科技';
    		defaultConf.kind = 'info';//confirm:显示取消按钮
    		defaultConf.type = 'info';
    		
    		//接收调用对话框的参数
    		//判断传入参数类型
    		var tf = typeof options;
    		if(tf=='undefined'){
        		$scope.options = defaultConf;
    		}
    		
    		if(tf=='object'){
            	$scope.options = options;
            	if(!$scope.options.title){
            		$scope.options.title = defaultConf.title;
            	}
            	if(!$scope.options.kind){
            		$scope.options.kind = defaultConf.kind;
            	}
            	if(!$scope.options.type){
            		$scope.options.type = defaultConf.type;
            	}
    		}
    		if(tf=='string'){
        		$scope.options = defaultConf;
        		$scope.options.statusMsg = options;
    		}

        });  
    	
    	
	    
	    Model.ok = function () {  
	        $uibModalInstance.close('ok');  
	    };    
	    
	    Model.cancel = function () {  
//	        $uibModalInstance.dismiss('cancel');  
	        $uibModalInstance.close('cancel');  
	    };    

	    $scope.showDetail = false;
	    Model.detailToggle = function(){
	    	$scope.showDetail = !$scope.showDetail;
	    }
    	
		return Model;
    }]);

    
    services.controller("dialogBillDoCtrl", ['$rootScope','$scope','$uibModalInstance','options','apiService'
    	,function ($rootScope,$scope,$uibModalInstance,options,apiService){
		
    	var Model = this;
    	
    	var enterpriseNo;
    	
    	$uibModalInstance.opened.then(function(){
    		
			console.log('options-->',options);
			
			$scope.okText = '确定';
    		$scope.cancelText = '取消';
        	
    		var defaultConf = new Object();
    		defaultConf.title = '云逸科技';
    		defaultConf.kind = 'info';//confirm:显示取消按钮
    		defaultConf.type = 'info';
    		defaultConf.approved = false;//不显示办理人
    		
    		//接收调用对话框的参数
    		//判断传入参数类型
    		var tf = typeof options;
    		if(tf=='undefined'){
        		$scope.options = defaultConf;
    		}
    		
    		if(tf=='object'){
            	$scope.options = options;
            	if(!$scope.options.title){
            		$scope.options.title = defaultConf.title;
            	}
            	if(!$scope.options.kind){
            		$scope.options.kind = defaultConf.kind;
            	}
            	if(!$scope.options.type){
            		$scope.options.type = defaultConf.type;
            	}
            	if(!$scope.options.approved){
            		$scope.options.approved = defaultConf.approved;
            	}
            	
            	enterpriseNo = options.enterpriseNo;
    			console.log('enterpriseNo-->',enterpriseNo);
    		}
    		if(tf=='string'){
        		$scope.options = defaultConf;
        		$scope.options.statusMsg = options;
    		}

        });  
    	
    	
    	$scope.content = null;
    	$scope.approveNo = null;
    	$scope.approveName = null;
	    
	    Model.ok = function () {  
	    	var event = {};
	    	event.content = $scope.content;
	    	event.approvedNo = $scope.approvedNo;
	    	event.approvedName = $scope.approvedName;

	        $uibModalInstance.close(event);  
	    };    
	    
	    Model.cancel = function () {  
	        $uibModalInstance.dismiss('cancel');  
//	        $uibModalInstance.close('cancel');  
	    };    


		//打开对话框（选择审批人）
		Model.triggerApprovedNoClick = function(){
			
//     		if($scope.approvedNo!=null && $scope.approvedNo!=''){
//     			$scope.approvedNo = null;
//     			return;
//     		}
			
			var options = {};
			options.id = enterpriseNo;
			//是否显示人员
			options.psm = true;
			options.validPsm = true;//是否验证选择的是否为人员成员

			var modalInstance = apiService.openOrgNoDialog(options);
			
	        //模态窗口关闭之后执行的事件
	        modalInstance.result.then(function (event) {  
	             //成功关闭窗口
	         	var returnData = event.data;
	         	//debugger;
	             try {
	             	for ( var i = 0; i < returnData.length; i++) {
//	             		alert(returnData[i].sID+'-->'+returnData[i].sFName);
	             		$scope.approvedNo = returnData[i].sFID;
	             		$scope.approvedName = returnData[i].sFName;
//	         			console.log($scope.approvedNo)
//	         			$scope.apply();
	                 }
	             } finally {
	             	return;
	             }

	        }, function (reason) {  
	            console.info('Modal dismissed at: ' + new Date());  
	        });  
			
		};
	    
    	
		return Model;
    }]);

    services.controller("dialogOpenBillCtrl", ['$rootScope', '$scope','$uibModalInstance','options',function f($rootScope,$scope,$uibModalInstance,options){
		
    	var Model = this;
    	
    	$uibModalInstance.opened.then(function(){
    		$scope.okText = '打开单据';
    		$scope.cancelText = '关闭窗口';
        	
    		var defaultConf = new Object();
    		defaultConf.title = '云逸科技';
    		defaultConf.kind = 'confirm';//confirm:显示关闭窗口按钮;info:不显示关闭窗口按钮
    		defaultConf.type = 'success';
    		
    		//接收调用对话框的参数
    		//判断传入参数类型
    		var tf = typeof options;
    		if(tf=='undefined'){
        		$scope.options = defaultConf;
    		}
    		
    		if(tf=='object'){
            	$scope.options = options;
            	if(!$scope.options.title){
            		$scope.options.title = defaultConf.title;
            	}
            	if(!$scope.options.kind){
            		$scope.options.kind = defaultConf.kind;
            	}
            	if(!$scope.options.type){
            		$scope.options.type = defaultConf.type;
            	}
    		}
    		if(tf=='string'){
        		$scope.options = defaultConf;
        		$scope.options.statusMsg = options;
    		}

        });  
    	
		//打开窗口
		Model.open = function(){
//			console.log('$scope.options-->',$scope.options);
			var appid = $scope.options.appID;
			var url = $scope.options.sProcess;
			var name = $scope.options.sName;
			var winParams = {};
			winParams.fID = $scope.options.fID;

//			winParams.type='FLOW';
			winParams.type='EDIT';
			
			$rootScope.menuClick(appid,url,name,winParams)
	
		};
    	
	    
	    Model.ok = function () {  
	        $uibModalInstance.close('ok');  
	        Model.open();
	    };    
	    
	    Model.cancel = function () {  
//	        $uibModalInstance.dismiss('cancel');  
	        $uibModalInstance.close('cancel');  
	    };    

	    $scope.showDetail = false;
	    Model.detailToggle = function(){
	    	$scope.showDetail = !$scope.showDetail;
	    }
    	
		return Model;
    }]);

    services.factory('systemService',['$rootScope', '$http', '$uibModal','$ocLazyLoad','OssEndpoint'
    	,function ($rootScope, $http, $uibModal, $ocLazyLoad,OssEndpoint){
    	
		var _self = this;

		//获取服务器日期
		var getCurrentDate = function(async){
			//async:异步调用参数，默认值为异步调用true
			var asyncParam = true;
			if(!angular.isDefined(async)){
				//参数值不存在
			}else{
				asyncParam = async;
			}
			var response = $.ajax({
	            type: "GET",
	            async : asyncParam,
	            url: $rootScope.getServiceName() + "/system/util/getCurrentDate",
//	            data: "{}",
	            contentType: "application/json; charset=utf-8",
	            dataType: "text",
//	            dataType: "json",
	            success: function (data) {
	                // Play with returned data in JSON format
	            	//console.log('getCurrentDate.data-->>',data);
	            },
	            error: function (msg) {
	                alert('错误信息：'+msg.responseText);
	            }
	        });
			if (response.readyState == 4 && response.status == 200) {
				return response.responseText;
//				return response.responseJSON;
			}else{
				return '';
			}
		};
		
		//获取服务器时间
		var getCurrentDateTime = function(async){
			//async:异步调用参数，默认值为异步调用true
			var asyncParam = true;
			if(!angular.isDefined(async)){
				//参数值不存在
			}else{
				asyncParam = async;
			}
			var response = $.ajax({
	            type: "GET",
	            async : asyncParam,
	            url: $rootScope.getServiceName() + "/system/util/getCurrentDateTime",
//	            data: "{}",
	            contentType: "application/json; charset=utf-8",
	            dataType: "text",
//	            dataType: "json",
	            success: function (data) {
	                // Play with returned data in JSON format
	            },
	            error: function (msg) {
	                alert('错误信息：'+msg.responseText);
	            }
	        });
			if (response.readyState == 4 && response.status == 200) {
				return response.responseText;
//				return response.responseJSON;
			}else{
				return '';
			}
		};
		
		//获取系统单据参数
		var getBillParam = function(data){
			var async = data.async;
			//async:异步调用参数，默认值为异步调用true
			var asyncParam = true;
			if(!angular.isDefined(async)){
			}else{
				asyncParam = async;
			}
			var response = $.ajax({
	            type: "GET",
	            async : asyncParam,
	            url: $rootScope.getServiceName() + "/system/systemBilltype/getBillParam",
	            data: {billType:data.billType,ognID:data.ognID},
	            contentType: "application/json; charset=utf-8",
	            dataType: "json",
	            success: function (data) {
	                // Play with returned data in JSON format
	            },
	            error: function (msg) {
	                alert('错误信息：'+msg.responseText);
	            }
	        });
			if (response.readyState == 4 && response.status == 200) {
//				return response.responseText;
				return response.responseJSON;
			}else{
				return '';
			}
		};
		
		//获取客户信息
		var getCustomerByNo = function(data){
			var async = data.async;
			//async:异步调用参数，默认值为异步调用true
			var asyncParam = true;
			if(!angular.isDefined(async)){
			}else{
				asyncParam = async;
			}
			var response = $.ajax({
	            type: "POST",
	            async : asyncParam,
	            url: $rootScope.getServiceName() + "/customer/getCustomerByNo",
	            data: JSON.stringify(data),
	            contentType: "application/json; charset=utf-8",
	            dataType: "json",
	            success: function (data) {
	                // Play with returned data in JSON format
	            },
	            error: function (msg) {
	                alert('错误信息：'+msg.responseText);
	            }
	        });
			if (response.readyState == 4 && response.status == 200) {
//				return response.responseText;
				return response.responseJSON;
			}else{
				return null;
			}
		};
		
		//获取供应商信息
		var getProviderByNo = function(data){
			var async = data.async;
			//async:异步调用参数，默认值为异步调用true
			var asyncParam = true;
			if(!angular.isDefined(async)){
			}else{
				asyncParam = async;
			}
			var response = $.ajax({
	            type: "POST",
	            async : asyncParam,
	            url: $rootScope.getServiceName() + "/provider/getProviderByNo",
	            data: JSON.stringify(data),
	            contentType: "application/json; charset=utf-8",
	            dataType: "json",
	            success: function (data) {
	                // Play with returned data in JSON format
	            },
	            error: function (msg) {
	                alert('错误信息：'+msg.responseText);
	            }
	        });
			if (response.readyState == 4 && response.status == 200) {
//				return response.responseText;
				return response.responseJSON;
			}else{
				return null;
			}
		};
		

		var rkckConfirmBefore = function(options){
			var dataDetail = options.bizData;
			console.log('dataDetail-->>',dataDetail);
			for(var i=0;i<dataDetail.getCount();i++){
				var rowID = dataDetail.getID(i);
				//判断批号
				var batchNo = dataDetail.getValue('batchNo',rowID);
				if(batchNo==null || batchNo==''){
					$rootScope.addAlert('danger' , '第'+(i+1)+'行批号不能为空！');
					return false;
				}
				//判断序号
				var storeNo = dataDetail.getValue('storeNo',rowID);
				if(storeNo==null || storeNo==''){
					$rootScope.addAlert('danger' , '第'+(i+1)+'行序列号不能为空！');
					return false;
				}
				//判断转移单的出入库地点
				var billType = dataDetail.getValue('billType',rowID);
				if(billType=='DBDJ' || billType=='GYTC' || billType=='GYZY' || billType=='GYRK'){
					var providerID = dataDetail.getValue('providerID',rowID);
					var storageID = dataDetail.getValue('storageID',rowID);
					if(providerID==null || providerID==''){
						$rootScope.addAlert('danger' , '第'+(i+1)+'行移出地点不能为空！');
						return false;
					}else if(storageID==null || storageID==''){
						$rootScope.addAlert('danger' , '第'+(i+1)+'行移入地点不能为空！');
						return false;
					}else if(providerID==storageID){
						$rootScope.addAlert('danger' , '第'+(i+1)+'行移入地点和移出地点不能相同！');
						return false;
					}
				}
				//判定发料单，工单号不能为空
				if(billType=='SCFL' || billType=='WWFL'){
					var workNo = dataDetail.getValue('workNo',rowID);
					if(workNo==null || workNo==''){
						$rootScope.addAlert('danger' , '第'+(i+1)+'行工单号不能为空！');
						return false;
					}
				}
				
				//判断物料号
				var itemID = dataDetail.getValue('itemID',rowID);
				if(itemID==null || itemID==''){
					$rootScope.addAlert('danger' , '第'+(i+1)+'行物料号不能为空！');
					return false;
				}
				//判断仓库
				var checkin = dataDetail.getValue('checkin',rowID);
				var storageID = dataDetail.getValue('storageID',rowID);
				if(checkin==1 && (storageID==null || storageID=='')){
					$rootScope.addAlert('danger' , '第'+(i+1)+'行仓库不能为空！');
					return false;
				}
			}
			
			//检查仓库是否合法
			var dataMaster = dataDetail.masterData;
			var rowID = dataMaster.getCurrentID();
			var storage = dataMaster.getValue('floorNo',rowID);
			var billType = dataMaster.getValue('billType',rowID);
			console.log('storage-->>',storage);
			if(storage && (billType=='QTRK' || billType=='QTRK' || billType=='CBKZ' 
				|| billType=='GYRK' || billType=='GYCK' 
				|| billType=='SCFL' || billType=='WWFL' || billType=='SCTL' || billType=='WWTL' 
				)){
				for(var i=0;i<dataDetail.getCount();i++){
					//判断仓库
					var rowID = dataDetail.getID(i);
					var checkin = dataDetail.getValue('checkin',rowID);
					var floorNo = dataDetail.getValue('floorNo',rowID);
					console.log('floorNo-->>',floorNo);
					if(checkin==1){
						var index = floorNo.indexOf(storage);
						console.log('index-->>',index);
						if(index!=0){
							$rootScope.addAlert('danger' , '第'+(i+1)+'行仓库不合法！');
							return false;
						}
					}
				}				
			}

			return true;
		};
		
		
		var ysyfConfirmBefore = function(options){
			var dataMaster = options.bizData;
			var rowID = dataMaster.getCurrentID();
			//判断资金账户
			var autoPayment = dataMaster.getValue('autoPayment',rowID);
			var capitalID = dataMaster.getValue('capitalID',rowID);
			if(autoPayment=='Y' && (capitalID==null || capitalID=='')){
				$rootScope.addAlert('danger' , '资金账户不能为空！');
				return false;
			}
			return true;
		};
		
		var skfkConfirmBefore = function(options){
			var dataMaster = options.bizData;
			var rowID = dataMaster.getCurrentID();
			//判断资金账户
			/*
			var capitalID = dataMaster.getValue('capitalID',rowID);
			if(capitalID==null || capitalID==''){
				$rootScope.addAlert('danger' , '资金账户不能为空！');
				return false;
			}
			*/
			return true;
		};
		
		var operateBill = function(data){
			var _self = this;
			var bizData = data.bizData;
			var url = data.url;
			//console.log('url-->>',url);
			
			var rowID = bizData.getCurrentID();
			var params = data.params;
			
			/*
			$http({
				method : 'GET'
				,url : url
				,params:  {'id':rowID,'params':params}
			}).success(function(data, status, headers, config) {
//				console.log('data-->',data);
				if(data && data.statusFlag=='failure'){
//					alert(data.statusInfo);
					data.type='danger';
					dialogMsg(data);
				}else{
	            	$rootScope.addAlert('success','操作成功！');
	            	bizData.refreshPageData();
				}
			
			}).error(function(data, status, headers, config) {
            	alert('操作失败！\r\n' + '返回的错误代码:' + status);
			});
			*/
			var options = {
					"id":rowID
			};
			//$.LoadingOverlay("show");
			$.ajax({
	            type: "POST",
	            async : false,//同步执行
	            url: url,
	            data: JSON.stringify(options),//{'id':rowID,'params':params},//"{}",
	            contentType: "application/json; charset=utf-8",
//	            dataType: "text",
	            dataType: "json",
	            success: function (data) {
	                // Play with returned data in JSON format
	            	console.log('services.operateBill.data-->>',data);
	            	if(data.code==0){
		            	bizData.refreshPageData();
		            	var status = '操作成功！';
		            	if(data && data.data){
		            		if(data.data.zdh)
		            		status = status + '账单号：'+ data.data.zdh;
		            	}
		            	$rootScope.addAlert('success',status);
	            	}else{
						data.type='danger';
						dialogMsg(data);
	            	}
	            }
	        });
			
		};
		
		//处理批准和撤销批准
		var doBill = function(data){
			var _self = this;
//			var bizData = data.bizData;
			var url = data.url;
//			
//			var rowID = bizData.getCurrentID();
//			var params = data.params;
			
			$http({
				method : 'POST'
				,url : url
				,data:  data//{'id':rowID,'params':params}
			}).success(function(data, status, headers, config) {
//				console.log('data-->',data);
				if(data && data.statusFlag=='failure'){
//					alert(data.statusInfo);
					data.type='danger';
					_self.dialogMsg(data);
				}else{
	            	$rootScope.addAlert('success','操作成功！');
//	            	bizData.refreshPageData();
	            	$rootScope.removeTab($rootScope.winid);
				}
			
			}).error(function(data, status, headers, config) {
            	alert('操作失败！\r\n' + '返回的错误代码:' + status);
			});
		};
		
		//打开对话框（选择地址信息）
//		var openRegionCodeDialog = function(options){
//	        var dlg = $uibModal.open({  
//	        	backdrop: 'static',
//	        	size: '',
//	            templateUrl: $rootScope.getProjectName() + '/baseinfo/regionInfo/selectSingle',  
//	            controller: 'regionInfoSelectSingleCtrl as Model',  
//	            resolve: {
//	                params: function () {  
//	                    return angular.copy(options);  
//	                }
//                    ,title : function() { return '选择'; }
//                    ,loadCtrl : $ocLazyLoad.load('js/baseinfo/regionInfo/selectSingle.js')
//		        }
//	        });  
//	        return dlg;
//		};
		
		//打开对话框（选择客户）
		var openCustomerNoDialog = function(options){

	        var dlg = $uibModal.open({
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/customer/customerInfo/selectSingle',  
	            controller: 'fileCustomerSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/customer/customerInfo/selectSingle')
		        }
	        }); 
	        return dlg;
		};
		
		//打开对话框（选择供应商）
		var openProviderNoDialog = function(options){

	        var dlg = $uibModal.open({
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/provider/providerInfo/selectSingle',  
	            controller: 'fileProviderSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/provider/providerInfo/selectSingle')
		        }
	        }); 
	        return dlg;
		};
		
		//打开对话框（选择物流公司）
		var openShipperNoDialog = function(options){

	        var dlg = $uibModal.open({
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/logistics/shipperInfo/selectSingle',  
	            controller: 'fileShipperSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/logistics/shipperInfo/selectSingle')
		        }
	        }); 
	        return dlg;
		};
		
		//打开对话框（选择优惠券）
		var openCouponNoDialog = function(options){

	        var dlg = $uibModal.open({
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/customer/memberCoupon/selectSingle',  
	            controller: 'memberCouponSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/customer/memberCoupon/selectSingle')
		        }
	        }); 
	        return dlg;
		};

		
		//打开对话框（选择客户地址、供应商地址、自提点儿，餐台、收银台等）
		var openFileAddressNoDialog = function(options){

	        var dlg = $uibModal.open({
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/logistics/fileAddressSelect/selectSingle',  
	            controller: 'fileAddressSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/logistics/fileAddressSelect/selectSingle')
		        }
	        }); 
	        return dlg;
		};
		
		//打开对话框（选择门店）
		var openPosNoDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	            templateUrl: $rootScope.getProjectName() + '/retail/filePos/selectSingle',  
	            controller: 'filePosSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/retail/filePos/selectSingle')
		        }
	        }); 
	        return dlg;
		};
		
		//打开对话框（选择门店）
		var openStoreCodeDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	            templateUrl: $rootScope.getProjectName() + '/retail/fileStore/selectSingle',  
	            controller: 'fileStoreSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/retail/fileStore/selectSingle')
		        }
	        }); 
	        return dlg;
		};
		
		//打开对话框（选择工厂）
		var openFactoryNoDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	            templateUrl: $rootScope.getProjectName() + '/baseinfo/fileFactory/selectSingle',  
	            controller: 'fileFactorySelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/baseinfo/fileFactory/selectSingle')
		        }
	        }); 
	        return dlg;
		};
		
		//打开对话框（选择工作中心）
		var openWorkcenterNoDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/baseinfo/fileWorkcenter/selectSingle',  
	            controller: 'fileWorkcenterSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/baseinfo/fileWorkcenter/selectSingle')
		        }
	        }); 
	        return dlg;
		};
		
		//打开对话框（选择物料档案）
		var openItemNoDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/inventory/fileItem/selectSingle',  
	            controller: 'fileItemSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/inventory/fileItem/selectSingle')
		        }
	        });  
	        return dlg;
		};
		
		//打开多选对话框（选择物料档案）
		var openItemNosDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/inventory/fileItem/selectMulti',  
	            controller: 'fileItemSelectMultiCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/inventory/fileItem/selectMulti')
		        }
	        });  
	        return dlg;
		};
		
		//打开对话框（选择批号）
		var openBatchNoDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/inventory/itemBatch/selectSingle',  
	            controller: 'itemBatchSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/inventory/itemBatch/selectSingle')
		        }
	        });  
	        return dlg;
		};
		
		//打开对话框（选择序号）
		var openStoreNoDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/inventory/itemStore/selectMulti',  
	            controller: 'itemStoreSelectMultiCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/inventory/itemStore/selectMulti')
		        }
	        });  
	        return dlg;
		};
		
		//打开对话框（选择仓库）
		var openStorageNoDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	            templateUrl: $rootScope.getProjectName() + '/inventory/fileStorage/selectSingle',  
	            controller: 'fileStorageSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/inventory/fileStorage/selectSingle')
		        }
	        });  
	        return dlg;
		};
		
		//打开对话框（选择仓库）
		var openStorageListDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	            templateUrl: $rootScope.getProjectName() + '/inventory/fileStorage/selectList',  
	            controller: 'fileStorageSelectListCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/inventory/fileStorage/selectList')
		        }
	        });  
	        return dlg;
		};
		
		//打开对话框（选择人员）
		var openPersonOgnNoDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	            templateUrl: $rootScope.getProjectName() + '/hrm/fileEmployee/selectSingle',  
	            controller: 'fileEmployeeSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/hrm/fileEmployee/selectSingle')
		        }
	        });  
	        return dlg;
		};
		
		//打开对话框（选择人员成员）
		var openPsmIDDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/usercenter/org/psmSelectSingle',  
	            controller: 'psmSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/usercenter/org/psmSelectSingle')
		        }
	        });  
	        return dlg;
		};

		//写入物料档案（单选），由openItemNoDialog调用
		var itemSelectSingle = function(simpleRow,dataDetail){
			//debugger;

			//alert(returnData[i].rowid+'-->'+returnData[i].billTypeName);
	    		
    		var rowID = dataDetail.getCurrentID();

			dataDetail.setValue('origin', simpleRow.billType, rowID);
			dataDetail.setValue('originName', simpleRow.billTypeName, rowID);
//			dataDetail.setValue('originNo', simpleRow.itemNo, rowID);
			
 			dataDetail.setValue('itemID', simpleRow.fID, rowID);
			dataDetail.setValue('itemNo', simpleRow.itemNo, rowID);
			dataDetail.setValue('itemDescribe', simpleRow.itemDescribe, rowID);
			dataDetail.setValue('itemName', simpleRow.itemName, rowID);
			dataDetail.setValue('checkin', simpleRow.checkin, rowID);
			dataDetail.setValue('itemProperty', simpleRow.itemProperty, rowID);
			dataDetail.setValue('unitCode', simpleRow.unitCode, rowID);
			dataDetail.setValue('unitName', simpleRow.unitName, rowID);
			dataDetail.setValue('process', simpleRow.process, rowID);
			dataDetail.setValue('processLabel', simpleRow.processLabel, rowID);
			dataDetail.setValue('qualityType', simpleRow.qualityType, rowID);
			dataDetail.setValue('qualityTypeLabel', simpleRow.qualityTypeLabel, rowID);

			dataDetail.setValue('qualityPeriod', simpleRow.qualityPeriod, rowID);
			dataDetail.setValue('validDays', simpleRow.validDays, rowID);
			dataDetail.setValue('checkoutAgainDays', simpleRow.checkoutAgainDays, rowID);
			
			dataDetail.setValue('storeNo', simpleRow.storeNo, rowID);
			dataDetail.setValue('batchNo', simpleRow.batchNo, rowID);
//			console.log('batchNo-->',simpleRow.batchNo);
			
			//质量检验
    		var billType = dataDetail.getValue('billType',rowID);
			var qualityType = dataDetail.getValue('qualityType',rowID);
			if(qualityType!=0){
				//非免检（工艺入库和工艺转移不使用这个函数）
				if(billType=='XSRK' || billType=='CGRK' || billType=='WWRK' || billType=='SCRK'/* || billType=='GYRK' || billType=='GYZY'*/){
					dataDetail.setValue('qualityStatus',1,rowID);
					dataDetail.setValue('qualityStatusLabel','1:待验',rowID);
				}else{
					dataDetail.setValue('qualityStatus',2,rowID);
					dataDetail.setValue('qualityStatusLabel','2:合格',rowID);
				}
			}else{
				dataDetail.setValue('qualityStatus',2,rowID);
				dataDetail.setValue('qualityStatusLabel','2:合格',rowID);
			}

    		//设置仓库
    		if (billType == 'DBDJ' 
    			|| billType == 'JCDJ'
        			|| billType == 'JCGH'
            			|| billType == 'JRDJ'
                			|| billType == 'JRGH'
                    			|| billType == 'BFDJ'
    			){
     			dataDetail.setValue('storageTypeD', simpleRow.storageType, rowID);
     			dataDetail.setValue('storageTypeDLabel', simpleRow.storageTypeLabel, rowID);
     			dataDetail.setValue('providerID', simpleRow.storageID, rowID);
     			dataDetail.setValue('providerNo', simpleRow.storageNo, rowID);
     			dataDetail.setValue('shortName', simpleRow.storageName, rowID);
     			dataDetail.setValue('providerName', simpleRow.floorNo, rowID);
     			dataDetail.setValue('procedureStepD', simpleRow.allowed, rowID);
     		}else if(billType == 'CBKZ' || billType == 'CBTZ'){
     			//成本开账/成本调整
     			dataDetail.setValue('storageType', simpleRow.storageType, rowID);
     			dataDetail.setValue('storageTypeLabel', simpleRow.storageTypeLabel, rowID);
     			dataDetail.setValue('storageID', simpleRow.storageID, rowID);
     			dataDetail.setValue('storageNo', simpleRow.storageNo, rowID);
     			dataDetail.setValue('storageName', simpleRow.storageName, rowID);
     			dataDetail.setValue('floorNo', simpleRow.floorNo, rowID);
    		}else{
     			dataDetail.setValue('storageType', simpleRow.storageType, rowID);
     			dataDetail.setValue('storageTypeLabel', simpleRow.storageTypeLabel, rowID);
     			dataDetail.setValue('storageID', simpleRow.storageID, rowID);
     			dataDetail.setValue('storageNo', simpleRow.storageNo, rowID);
     			dataDetail.setValue('storageName', simpleRow.storageName, rowID);
     			dataDetail.setValue('floorNo', simpleRow.floorNo, rowID);
     			//仓库表
     			dataDetail.setValue('procedureStep', simpleRow.allowed, rowID);
     			//订单表
     			dataDetail.setValue('allowed', simpleRow.allowed, rowID);
    		}
    			
    		//设置单价
    		var itemPrice;
    		if (billType == 'XSCK' //销售发货单
    			|| billType == 'XSRK' //销售退货单
        			|| billType == 'XSDD' //销售订单
            			|| billType == 'JXDJ' //叫修单
                			|| billType == 'WXFL'//维修发料
                    			|| billType == 'LSCK'//零售单
                    				|| billType == 'WXBJ'
	                    				|| billType == 'XSBJ'//销售报价单
		                    				|| billType == 'XSYC'//销售预测
    				){
    			dataDetail.setValue('itemPrice', simpleRow.salePrice, rowID);
    		}else{
    			dataDetail.setValue('itemPrice', simpleRow.purchasePrice, rowID);
    		}
    		
    		//设置数量
    		/*
    		if (billType == 'PDDJ'){
	       		dataDetail.setValue('itemAmount', 0, rowID);
    		}else{
	       		dataDetail.setValue('itemAmount', 1, rowID);
    		}
    		*/
    		//dataDetail.setValue('itemAmount', 0, rowID);
    		
    		//处理成本
    		/*
			if ( (billType=="PDDJ" || billType=="QTRK" || billType=="QTCK")
					|| (billType=="XSCK" || billType=="XSRK")
					|| (billType=="SCFL" || billType=="SCTL")
					|| (billType=="WWFL" || billType=="WWTL")
					|| (billType=="SCRK" || billType=="SCCK")
					|| (billType=="DBDJ" || billType=="BFDJ")
					){
				//实际单位成本赋值
    			dataDetail.setValue('costingAmountPer', simpleRow.costingAmountPer, rowID);
			}
			*/
			//不用上面的处理方式，因为单价变动之后可以冲掉单位成本
			dataDetail.setValue('costingAmountPer', simpleRow.costingAmountPer, rowID);
			//alert(simpleRow.costingAmountPer);
    		
			
		};
		
		//打开多选对话框（选择工单）
		var openWorkOrderDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/work/workOrder/selectMulti',  
	            controller: 'workOrderSelectMultiCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/work/workOrder/selectMulti')
		        }
	        });  
	        return dlg;
		};
		
		//打开多选对话框（选择配料单）
		var openWorkMaterialDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/work/workMaterialSelect/selectMulti',  
	            controller: 'workMaterialSelectMultiCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/work/workMaterialSelect/selectMulti')
		        }
	        });  
	        return dlg;
		};
		
		//打开单选对话框（选择生产入库单、委外进货单、采购进货单、工艺入库单和销售退货单，用于质量检验）
		var openRecordDetailQualityDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/inventory/recordDetailQualitySelect/selectSingle',  
	            controller: 'recordDetailQualitySelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/inventory/recordDetailQualitySelect/selectSingle')
		        }
	        });  
	        return dlg;
		};
		
		//打开多选对话框（选择销售出入库、采购、委外进退货）
		var openRecordDetailInvoiceDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/inventory/recordDetailInvoiceSelect/selectMulti',  
	            controller: 'recordDetailInvoiceSelectMultiCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/inventory/recordDetailInvoiceSelect/selectMulti')
		        }
	        });  
	        return dlg;
		};
		
		//打开多选对话框（选择销售出入库、采购、委外进退货）
		var openRecordDetailInvgyrkDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/inventory/recordDetailInvgyrkSelect/selectMulti',  
	            controller: 'recordDetailInvgyrkSelectMultiCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/inventory/recordDetailInvgyrkSelect/selectMulti')
		        }
	        });  
	        return dlg;
		};
		
		//打开多选对话框（选择生产出入库单，通用）
		var openRecordDetailDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/inventory/recordDetailSelect/selectMulti',  
	            controller: 'recordDetailSelectMultiCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/inventory/recordDetailSelect/selectMulti')
		        }
	        });  
	        return dlg;
		};
		
		//打开多选对话框（选择应收应付）
		var openInvoiceDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/invoice/invoiceSelect/selectMulti',  
	            controller: 'invoiceSelectMultiCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/invoice/invoiceSelect/selectMulti')
		        }
	        });  
	        return dlg;
		};
		
		//打开多选对话框（选择预收预付）
		var openPaymentDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/invoice/paymentSelect/selectMulti',  
	            controller: 'paymentSelectMultiCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/invoice/paymentSelect/selectMulti')
		        }
	        });  
	        return dlg;
		};

		var qualityDialogReceive = function (simpleRow,dataMaster){
			var rowID = dataMaster.getCurrentID();
			
			dataMaster.setValue('origin',simpleRow.billType,rowID);
			dataMaster.setValue('originName',simpleRow.billTypeName,rowID);
			dataMaster.setValue('originNo',simpleRow.recordNo,rowID);
			dataMaster.setValue('originSerialNo',simpleRow.serialNo,rowID);
			
			//获取并计算checkOuttimes
			/*
			var checkoutTimes = simpleRow.checkoutTimes;
			if(checkoutTimes=='' || checkoutTimes==null){
				checkoutTimes = '0';
			}
			var times = parseInt(checkoutTimes);
			times++;
			checkoutTimes = times.toString();
			checkoutTimes = common.padLeft(checkoutTimes,5);
			
			dataMaster.setValue('checkoutTimes',checkoutTimes,rowID);
			*/
			dataMaster.setValue('checkoutTimes','00001',rowID);
			
			dataMaster.setValue('arriveAmount',simpleRow.arriveAmount,rowID);
			dataMaster.setValue('itemAmount',simpleRow.itemAmount,rowID);
			dataMaster.setValue('priceAmount',simpleRow.priceAmount,rowID);
			
			dataMaster.setValue('itemNo',simpleRow.itemNo,rowID);
			dataMaster.setValue('itemName',simpleRow.itemName,rowID);
			dataMaster.setValue('itemDescribe',simpleRow.itemDescribe,rowID);
			dataMaster.setValue('itemProperty',simpleRow.itemProperty,rowID);
			dataMaster.setValue('unitCode',simpleRow.unitCode,rowID);
			dataMaster.setValue('unitName',simpleRow.unitName,rowID);
		    		     
//					dataMaster.setValue('process',simpleRow.process,rowID);
//					dataMaster.setValue('processLabel',simpleRow.processLabel,rowID);
//					dataMaster.setValue('costingType',simpleRow.costingType,rowID);
			dataMaster.setValue('qualityType',simpleRow.qualityType,rowID);
			dataMaster.setValue('qualityTypeLabel',simpleRow.qualityTypeLabel,rowID);
//					dataMaster.setValue('qualityPeriod',simpleRow.qualityPeriod,rowID);
//					dataMaster.setValue('validDays',simpleRow.validDays,rowID);
//					dataMaster.setValue('checkoutAgainDays',simpleRow.checkoutAgainDays,rowID);
			
			dataMaster.setValue('providerID',simpleRow.providerID,rowID);
			dataMaster.setValue('providerNo',simpleRow.providerNo,rowID);
			dataMaster.setValue('shortName',simpleRow.shortName,rowID);
			dataMaster.setValue('providerName',simpleRow.providerName,rowID);
			
			dataMaster.setValue('storageID',simpleRow.storageID,rowID);
			dataMaster.setValue('storageNo',simpleRow.storageNo,rowID);
			dataMaster.setValue('storageName',simpleRow.storageName,rowID);
			dataMaster.setValue('floorNo',simpleRow.floorNo,rowID);
	
			dataMaster.setValue('batchNo',simpleRow.batchNo,rowID);
			dataMaster.setValue('batchDescribe',simpleRow.batchDescribe,rowID);
			
//					dataMaster.setValue('produceDate',simpleRow.produceDate,rowID);
//					dataMaster.setValue('validDate',simpleRow.validDate,rowID);
//					dataMaster.setValue('checkoutAgainDate',simpleRow.checkoutAgainDate,rowID);
			
			dataMaster.setValue('brand',simpleRow.brand,rowID);
			dataMaster.setValue('brandLabel',simpleRow.brandLabel,rowID);
			dataMaster.setValue('placeOrigin',simpleRow.placeOrigin,rowID);
			dataMaster.setValue('manufacturer',simpleRow.manufacturer,rowID);

			dataMaster.setValue('storeNo',simpleRow.storeNo,rowID);
			
			dataMaster.setValue('billDate',simpleRow.orderDate,rowID);
			
			dataMaster.setValue('workNo',simpleRow.workNo,rowID);
			

		};

		
		//打开对话框（选择会计科目）
		var openCaptionNoDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	            templateUrl: $rootScope.getProjectName() + '/accounting/accountCaption/selectSingle',  
	            controller: 'accountCaptionSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/accounting/accountCaption/selectSingle')
		        }
	        });  
	        return dlg;
		};
		
		//打开单选对话框（选择客户订单）
		var openSaleOrderDialog = function(options){
	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/sale/saleOrder/selectSingle',  
	            controller: 'saleOrderSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/sale/saleOrder/selectSingle')
		        }
	        });  
	        return dlg;
		};
		
		//打开多选对话框（选择客户订单，用于预收款单）
		/*
		var openSaleOrderDialog = function(options){
	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: '/sale/saleOrder/selectMulti',  
	            controller: 'saleOrderSelectMultiCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/sale/saleOrder/selectMulti')
		        }
	        });  
	        return dlg;
		};
		*/
		
		//打开多选对话框（选择客户订单明细表）
		var openSaleOrderDetailDialog = function(options){
	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/sale/orderDetailSelect/selectMulti',  
	            controller: 'saleOrderDetailSelectMultiCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/sale/orderDetailSelect/selectMulti')
		        }
	        });  
	        return dlg;
		};
		
		//打开单选对话框（选择采购订单，用于预付款单）
		var openPurchaseOrderDialog = function(options){
	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/purchase/purchaseOrder/selectSingle',  
	            controller: 'purchaseOrderSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/purchase/purchaseOrder/selectSingle')
		        }
	        });  
	        return dlg;
		};
		
		//打开多选对话框（选择采购订单，用于预付款单）
		/*
		var openPurchaseOrderDialog = function(options){
	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: '/purchase/purchaseOrder/selectMulti',  
	            controller: 'purchaseOrderSelectMultiCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/purchase/purchaseOrder/selectMulti')
		        }
	        });  
	        return dlg;
		};
		*/
		
		//打开多选对话框（选择采购订单明细表）
		var openPurchaseOrderDetailDialog = function(options){
	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/purchase/orderDetailSelect/selectMulti',  
	            controller: 'purchaseOrderDetailSelectMultiCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/purchase/orderDetailSelect/selectMulti')
		        }
	        });  
	        return dlg;
		};
		
		//打开单选对话框（选择工单工艺）
		var openWorkProcedureDialog = function(options){
	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/manufact/workProcedure/selectSingle',  
	            controller: 'workProcedureSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/manufact/workProcedure/selectSingle')
		        }
	        });  
	        return dlg;
		};
		
		//打开多选对话框（选择工单工艺）
		var openWorkProceduresDialog = function(options){
	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/manufact/workProcedure/selectMulti',  
	            controller: 'workProcedureSelectMultiCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/manufact/workProcedure/selectMulti')
		        }
	        });  
	        return dlg;
		};
		
		//打开对话框（配置物料属性）//作废，被下面的代替啦
		var openBomElementDialog = function(options){
	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	            templateUrl: $rootScope.getProjectName() + '/product/bom/selectElement',  
	            controller: 'bomElementSelectCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/product/bom/selectElement')
		        }
	        });  
	        return dlg;
		};
		
		//打开对话框（配置物料属性）
		var openItemClassStandardDialog = function(options){
	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	            templateUrl: $rootScope.getProjectName() + '/inventory/itemClass/selectStandard',  
	            controller: 'itemClassDetailSelectCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/inventory/itemClass/selectStandard')
		        }
	        });  
	        return dlg;
		};
		
		//打开单选对话框（Bom主件列表）
		var openBomMainDialog = function(options){
	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/product/itemBom/selectMain',  
	            controller: 'itemBomSelectMainCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/product/itemBom/selectMain')
		        }
	        });  
	        return dlg;
		};
		//打印
		var openPrintWindow = function(data){
			var root = data.root;
			var path = data.path;
			var url = root + "/run?__report=" + path + ".rptdesign";
			var id = data.id;
			if(id){
				url = url + "&id=" + id;
			}
//			console.log(url);
			window.open(url);
		};
		
		//打印导出
		var openPrintExportWindow = function(data){
			//console.log('openPrintExportWindow.data-->>',data);
			var path = data.path;
			var url = path;
			var id = data.id;
			if(id){
				url = url + "?id=" + id;
			}
//			console.log(url);
//			window.open("/u2/sale/saleOrder/single/printPDF?id=" + Model.dataMaster.getCurrentID(), "_blank");	
//			window.open(url);
			window.open(url, "_blank");
		};
		
		
		//下载打印
		var downloadExport = function(options){
			//console.log('downloadExport.options-->>',options);
			var path = options.path;
			var url = path ;
			var id = options.id;
			if(id){
				url = url + "?id=" + id;
			}
			
			//console.log("ajaxDownloadSynchronized");
//	        var url = "http://127.0.0.1:80/erp01/sale/saleOrder/single/downloadPDF?id=5a7667062f584ae2a2e31338956b4658";
//	        var fileName = "testAjaxDownload.pdf";
//	        var form = $("<form></form>").attr("action", url).attr("method", "post");
//	        form.append($("<input></input>").attr("type", "hidden").attr("name", "fileName").attr("value", fileName));
//	        form.appendTo('body').submit().remove();
	        
	        /*
	        var action = "http://127.0.0.1:80/erp01/sale/saleOrder/single/downloadPDF?id=5a7667062f584ae2a2e31338956b4658";
		    var postForm = document.createElement("form");//表单对象
			postForm.method="post" ;
			postForm.action = action ;
			postForm.name="downloadFile";
			 
//			var WIDout_trade_noInput = document.createElement("input") ; //商户订单号 input
//			WIDout_trade_noInput.setAttribute("name", "id") ;
//			WIDout_trade_noInput.setAttribute("value", id);
//			postForm.appendChild(WIDout_trade_noInput) ;
			
			document.body.appendChild(postForm) ;
			postForm.submit() ;
			document.body.removeChild(postForm) ;
			*/
			
	        //var url = $rootScope.getServiceName()+"/sale/saleOrder/single/printPDF?id=5a7667062f584ae2a2e31338956b4658";
			function saveFile(url) {
			    // Get file name from url.
			    //var filename = url.substring(url.lastIndexOf("/") + 1).split("?")[0];
			    filename = id + '.pdf';
			    //console.log('filename-->>',filename);
				return new Promise(function(resolve, reject) {
				    var xhr = new XMLHttpRequest();
				    xhr.responseType = 'blob';
				    xhr.onload = function() {
				      resolve(xhr);
				    };
				    xhr.onerror = reject;
				    xhr.open('GET', url);
	                
					var sid = localStorage.getItem('sid');
	  				//console.log('sid-->>',sid);
			    	xhr.setRequestHeader("X-Requested-With","XMLHttpRequest");//代表是ajax访问
					xhr.setRequestHeader("sid", sid);//shiro sessionid
	
					xhr.send();
				}).then(function(xhr) {
				    //console.log('xhr-->>',xhr);
				    var a = document.createElement('a');
				    a.href = window.URL.createObjectURL(xhr.response); // xhr.response is a blob
				    a.download = filename; // Set the file name.
				    a.style.display = 'none';
				    document.body.appendChild(a);
				    a.click();
				    return xhr;
				});
			}
			
			/*
			function download(urls) {
			  return Promise.all(urls.map(saveFile));
			}
			*/

			saveFile(url);

		};
		

		//打开对话框（现结）
		var openCashSettleDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: '',
	        	keyboard: false,//按ESC键不关闭窗口
	            templateUrl: $rootScope.getProjectName() + '/invoice/cashSettle/single',  
	            controller: 'cashSettleSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '现结'; }
                    ,loadCtrl : $ocLazyLoad.load('js/invoice/cashSettle/single.js')
		        }
	        });  
	        return dlg;
		};


		
		/////////////////////////////////////////////////////////////////////////////////////
		/////////////////////////////////////////////////////////////////////////////////////
		/////////////////////////////////////////////////////////////////////////////////////

		
		
		/////////////////////////////////////////////////////////////////////////////////////
		/////////////////////////////////////////////////////////////////////////////////////
		/////////////////////////////////////////////////////////////////////////////////////
		
		//打开对话框（单选设备档案）
		var openDeviceNoDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/factory/deviceInfo/selectSingle',  
	            controller: 'deviceInfoSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/factory/deviceInfo/selectSingle')
		        }
	        });  
	        return dlg;
		};
		
		//打开对话框（多选设备档案）
		var openDeviceNosDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/factory/deviceInfo/selectMulti',  
	            controller: 'deviceInfoSelectMultiCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/factory/deviceInfo/selectMulti')
		        }
	        });  
	        return dlg;
		};
		
		
		//打开对话框（单选资产档案）
		var openAssetsNoDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/assets/assetsInfo/selectSingle',  
	            controller: 'assetsInfoSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/assets/assetsInfo/selectSingle')
		        }
	        });  
	        return dlg;
		};
		
		//打开对话框（多选资产档案）
		var openAssetsNosDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/assets/assetsInfo/selectMulti',  
	            controller: 'assetsInfoSelectMultiCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/assets/assetsInfo/selectMulti')
		        }
	        });  
	        return dlg;
		};

		//写入资产档案（单选），由openAssetsNoDialog调用
		var assetsSelectSingle = function(simpleRow,dataDetail){
//			var returnData = event.data;
			//debugger;
		    try {
	    		//alert(returnData[i].rowid+'-->'+returnData[i].billTypeName);
	    		
	    		var rowID = dataDetail.getCurrentID();

				dataDetail.setValue('origin', simpleRow.billType, rowID);
				dataDetail.setValue('originName', simpleRow.billTypeName, rowID);
				dataDetail.setValue('originNo', simpleRow.assetsNo, rowID);
				
     			dataDetail.setValue('itemID', simpleRow.fID, rowID);
				dataDetail.setValue('itemNo', simpleRow.assetsNo, rowID);
				dataDetail.setValue('itemName', simpleRow.assetsName, rowID);
				dataDetail.setValue('itemProperty', simpleRow.modelNo, rowID);
				dataDetail.setValue('itemDescribe', simpleRow.assetsDescribe, rowID);
				dataDetail.setValue('unitName', simpleRow.unitName, rowID);
				dataDetail.setValue('qualityPeriod',simpleRow.qualityPeriod,rowID);
//				dataDetail.setValue('validDays', simpleRow.validDays, rowID);
//				dataDetail.setValue('checkoutAgainDays', simpleRow.checkoutAgainDays, rowID);

				dataDetail.setValue('storeNo', simpleRow.storeNo, rowID);
//				dataDetail.setValue('batchNo', '********************', rowID);
//				dataDetail.setValue('storeNo', '********************', rowID);
				
//				dataDetail.setValue('produceDate', simpleRow.produceDate, rowID);
//				dataDetail.setValue('validDate', simpleRow.validDate, rowID);
//				dataDetail.setValue('checkoutAgainDate', simpleRow.checkoutAgainDate, rowID);

				dataDetail.setValue('itemWeight', simpleRow.itemWeight, rowID);
				dataDetail.setValue('itemSize', simpleRow.itemSize, rowID);
				dataDetail.setValue('orderWeight', simpleRow.orderWeight, rowID);
				dataDetail.setValue('orderSize', simpleRow.orderSize, rowID);

	    		//设置单价
	    		dataDetail.setValue('itemPrice', simpleRow.itemPrice, rowID);
	    		dataDetail.setValue('itemAmount', 1, rowID);
		    } finally {
		    	return;
		    }
			
		};
		
		//打开对话框（单选资产档案）
		var openProcedureNoDialog = function(options){

	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
	        	size: 'lg',
	            templateUrl: $rootScope.getProjectName() + '/baseinfo/fileProcedure/selectSingle',  
	            controller: 'fileProcedureSelectSingleCtrl as Model',  
	            resolve: {
	                params: function () {  
	                    return angular.copy(options);  
	                }
                    ,title : function() { return '选择'; }
                    ,loadCtrl : $ocLazyLoad.load('js/baseinfo/fileProcedure/selectSingle')
		        }
	        });  
	        return dlg;
		};

		//弹出消息对话框（info）
		var dialogMsg = function(options){

//			var options = new Object();
//			options.msg = msg;
//			options.info = info;
			
	        var dlg = $uibModal.open({  
	        	backdrop: '',//'static',
	        	size: '',
	            templateUrl: 'js/_services/systemService-dialogMsg.html',  
	            controller: 'dialogMsgCtrl as Model',  
	            resolve: {
	            	options: function () {  
	                    return angular.copy(options);  
	                }
//                    ,msg : function() { return msg; }
//	        		,loadCtrl : $ocLazyLoad.load('js/_services/systemService-dialogMsg.html')
		        }
	        });  
	        return dlg;
		};
		
		//弹出办理对话框
		var dialogBillDo = function(options){

//			var options = new Object();
//			options.msg = msg;
//			options.info = info;
			
	        var dlg = $uibModal.open({  
	        	backdrop: 'static',
//	        	size: 'sm',
	            templateUrl: 'js/_services/systemService-dialogBillDo.html',  
	            controller: 'dialogBillDoCtrl as Model',  
	            resolve: {
	            	options: function () {  
	                    return angular.copy(options);  
	                }
//                    ,msg : function() { return msg; }
//                	,loadCtrl : $ocLazyLoad.load('js/_services/systemService-dialogBillDo.html')
		        }
	        });  
	        return dlg;
		};

		//弹出消息对话框（附带打开单据功能）
		var dialogOpenBill = function(options){

//			var options = new Object();
//			options.msg = msg;
//			options.info = info;
			
	        var dlg = $uibModal.open({  
	        	backdrop: '',//'static',
	        	size: '',
	            templateUrl: 'js/_services/systemService-dialogOpenBill.html',  
	            controller: 'dialogOpenBillCtrl as Model',  
	            resolve: {
	            	options: function () {  
	                    return angular.copy(options);  
	                }
//                    ,msg : function() { return msg; }
//	        		,loadCtrl : $ocLazyLoad.load('js/_services/systemService-dialogMsg.html')
		        }
	        });  
	        return dlg;
		};

		
		return {
			getCurrentDate: function(async){
				return getCurrentDate(async);
			},
			getCurrentDateTime: function(async){
				return getCurrentDateTime(async);
			},
			getBillParam: function(data){
				return getBillParam(data);
			},
			getCustomerByNo: function(data){
				return getCustomerByNo(data);
			},
			getProviderByNo: function(data){
				return getProviderByNo(data);
			},
			//单据提交操作前调用
			rkckConfirmBefore: function(options){
				return rkckConfirmBefore(options);
			},
			//单据提交操作前调用
			ysyfConfirmBefore: function(options){
				return ysyfConfirmBefore(options);
			},
			//单据提交操作前调用
			skfkConfirmBefore: function(options){
				return skfkConfirmBefore(options);
			},
			//单据通用操作调用
			operateBill: function(data){
				return operateBill(data);
			},
			//单据通用操作调用
			doBill: function(data){
				return doBill(data);
			},
			//打开对话框（选择地址信息）
//			openRegionCodeDialog: function(options){
//				return openRegionCodeDialog(options);
//			},
			//打开对话框（选择客户单选）
			openCustomerNoDialog: function(options){
				return openCustomerNoDialog(options);
			},
			//打开对话框（选择供应商单选）
			openProviderNoDialog: function(options){
				return openProviderNoDialog(options);
			},
			//打开对话框（选择物流公司单选）
			openShipperNoDialog: function(options){
				return openShipperNoDialog(options);
			},
			//打开对话框（选择优惠券单选）
			openCouponNoDialog: function(options){
				return openCouponNoDialog(options);
			},
			//打开对话框（选择自提点二单选）
			openFileAddressNoDialog: function(options){
				return openFileAddressNoDialog(options);
			},
			//打开对话框（选择门店单选）
			openPosNoDialog: function(options){
				return openPosNoDialog(options);
			},
			//打开对话框（选择门店单选）
			openStoreCodeDialog: function(options){
				return openStoreCodeDialog(options);
			},
			//打开对话框（选择工厂单选）
			openFactoryNoDialog: function(options){
				return openFactoryNoDialog(options);
			},
			//打开对话框（选择工作中心单选）
			openWorkcenterNoDialog: function(options){
				return openWorkcenterNoDialog(options);
			},
			//打开对话框（选择物料单选）
			openItemNoDialog: function(options){
				return openItemNoDialog(options);
			},
			//打开对话框（选择物料多选）
			openItemNosDialog: function(options){
				return openItemNosDialog(options);
			},
			//打开对话框（选择批号）
			openBatchNoDialog: function(options){
				return openBatchNoDialog(options);
			},
			//打开对话框（选择序号）
			openStoreNoDialog: function(options){
				return openStoreNoDialog(options);
			},
			//打开对话框（选择仓库单选）
			openStorageNoDialog: function(options){
				return openStorageNoDialog(options);
			},
			//打开对话框（选择仓库列表单选）
			openStorageListDialog: function(options){
				return openStorageListDialog(options);
			},
			//打开对话框（选择人员）
			openPersonOgnNoDialog: function(options){
				return openPersonOgnNoDialog(options);
			},
			//打开对话框（选择人员成员）
			openPsmIDDialog: function(options){
				return openPsmIDDialog(options);
			},
			//写入物料档案（单选），由openItemNoDialog调用
			itemSelectSingle: function(simpleRow,dataDetail){
				return itemSelectSingle(simpleRow,dataDetail);
			},
			//打开多选对话框（选择工单）
			openWorkOrderDialog: function(options){
				return openWorkOrderDialog(options);
			},
			//打开多选对话框（选择配料单）
			openWorkMaterialDialog: function(options){
				return openWorkMaterialDialog(options);
			},
			//打开单选对话框（选择生产入库单、委外进货单、采购进货单、工艺入库单和销售退货单，用于质量检验）
			openRecordDetailQualityDialog: function(options){
				return openRecordDetailQualityDialog(options);
			},
			//打开多选对话框（选择销售出入库、采购、委外进退货）
			openRecordDetailInvoiceDialog: function(options){
				return openRecordDetailInvoiceDialog(options);
			},
			//打开多选对话框（选择工艺入库单）
			openRecordDetailInvgyrkDialog: function(options){
				return openRecordDetailInvgyrkDialog(options);
			},
			//打开多选对话框（选择生产出入库单，通用）
			openRecordDetailDialog: function(options){
				return openRecordDetailDialog(options);
			},
			//打开多选对话框（选择应收应付）
			openInvoiceDialog: function(options){
				return openInvoiceDialog(options);
			},
			//打开多选对话框（选择预收预付）
			openPaymentDialog: function(options){
				return openPaymentDialog(options);
			},
			qualityDialogReceive:function(simpleRow,dataMaster){
				return qualityDialogReceive(simpleRow,dataMaster);
			},
			//打开单选对话框（选择会计科目）
			openCaptionNoDialog: function(options){
				return openCaptionNoDialog(options);
			},
			//打开单选对话框（选择销售订单，为预收款单使用）
//			openSaleOrderDialog: function(options){
//				return _self.openSaleOrderDialog(options);
//			},
			//打开单多对话框（选择销售订单，为预收款单使用）
			openSaleOrderDialog: function(options){
				return openSaleOrderDialog(options);
			},
			//打开单多对话框（选择销售订单）
			openSaleOrderDetailDialog: function(options){
				return openSaleOrderDetailDialog(options);
			},
			//打开单多对话框（选择采购订单，为预付款单使用）
			openPurchaseOrderDialog: function(options){
				return openPurchaseOrderDialog(options);
			},
			//打开单多对话框（选择采购订单）
			openPurchaseOrderDetailDialog: function(options){
				return openPurchaseOrderDetailDialog(options);
			},
			//打开单对话框（选择工单工艺）
			openWorkProcedureDialog: function(options){
				return openWorkProcedureDialog(options);
			},
			//打开多对话框（选择工单工艺）
			openWorkProceduresDialog: function(options){
				return openWorkProceduresDialog(options);
			},
			
			//打开对话框（配置物料属性）//作废，被下面的代替啦
			openBomElementDialog: function(options){
				return openBomElementDialog(options);
			},
			//打开对话框（配置物料属性）
			openItemClassStandardDialog: function(options){
				return openItemClassStandardDialog(options);
			},
			//打开单选对话框（Bom主件列表）
			openBomMainDialog: function(options){
				return openBomMainDialog(options);
			},
			//打印
			openPrintWindow: function(options){
				return openPrintWindow(options);
			},
			//打印导出
			openPrintExportWindow: function(options){
				return openPrintExportWindow(options);
			},
			//下载打印
			downloadExport: function(options){
				return downloadExport(options);
			},
			//打开对话框（现结）
			openCashSettleDialog: function(options){
				return openCashSettleDialog(options);
			},
			//打开对话框（选择隶属于组织）
			openOrgNoDialog: function(options){
				return openOrgNoDialog(options);
			},
			//打开对话框（选择行业分类）
//			openTradeCodeDialog: function(options){
//				return openTradeCodeDialog(options);
//			},
			
			//打开对话框（单选设备档案）
			openDeviceNoDialog: function(options){
				return openDeviceNoDialog(options);
			},
			//打开对话框（多选设备档案）
			openDeviceNosDialog: function(options){
				return openDeviceNosDialog(options);
			},
			//打开对话框（单选资产档案）
			openAssetsNoDialog: function(options){
				return openAssetsNoDialog(options);
			},
			//打开对话框（多选资产档案）
			openAssetsNosDialog: function(options){
				return openAssetsNosDialog(options);
			},
			//写入资产档案（单选），由openAssetsNoDialog调用
			assetsSelectSingle: function(simpleRow,dataDetail){
				return assetsSelectSingle(simpleRow,dataDetail);
			},
			//打开对话框（单选工艺档案）
			openProcedureNoDialog: function(options){
				return openProcedureNoDialog(options);
			},
			//弹出消息对话框（info）
			dialogMsg: function(options){
				return dialogMsg(options);
			},
			//弹出办理对话框
			dialogBillDo: function(options){
				return dialogBillDo(options);
			},
			//弹出消息对话框（附带打开单据功能）
			dialogOpenBill: function(options){
				return dialogOpenBill(options);
			}
		};
	}])
   
});